• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Background location in SG Buses

  • 4,424 views
Uploaded on

This is a presentation on background location in iOS 4.0 used in SG Buses. …

This is a presentation on background location in iOS 4.0 used in SG Buses.

Presented this at 'Adopting Multitasking in iOS4' seminar at Apple Singapore, 2nd Nov 2010

More in: Self Improvement
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
4,424
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
43
Comments
1
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • - 1st bus guide\n- Dec 2007, Transit b4 AppStore July 2008\n- not XCode\n- 350,000 downloads since version 2.0\n- bus guide -> arrival time (SBS SMRT)\n- added background arrival time in a recent update 3 weeks ago, but started testing since June\n\nNEXT: about multitasking in iOS4 enabling background arrival time\n
  • - iOS4.0 introduced multitasking\n1) users can set alert for buses at a particular bus stops\n- background location to detect if users is near a particular bus stop\n\n2) task completion API to download the arrival time\n\n3) use local notification to display a popup when the app is still in the background\n\nNEXT: about significant location change API\n
  • 1) app notified when cell tower changes\n\n2) accuracy between 500m and 3km\n\n4) the current version only supports background arrival time using significant location changes\n- future version may include region monitoring that is for iPhone 4 only\n- no success with iPad running 4.2\n\nNEXT: code use to start and stop the API\n
  • - start monitoring when app exits, and stop monitoring when app starts\n\nNEXT: check application state when getting arrival data\n
  • - start monitoring when app exits, and stop monitoring when app starts\n\nNEXT: check application state when getting arrival data\n
  • - start monitoring when app exits, and stop monitoring when app starts\n\nNEXT: check application state when getting arrival data\n
  • - start monitoring when app exits, and stop monitoring when app starts\n\nNEXT: check application state when getting arrival data\n
  • - the same delegate callback method gives feedback when location is updated\n- check application state to determine if the application is active or not active\n- download bus arrival time if application is not active\n\nNEXT: Task Completion - > arrival time\n
  • - the same delegate callback method gives feedback when location is updated\n- check application state to determine if the application is active or not active\n- download bus arrival time if application is not active\n\nNEXT: Task Completion - > arrival time\n
  • - Task Completion API, block to indicate start and end of a long running task\n- Method called if task is not completed\n\nNEXT: fail->notification, success->notification\n
  • - Task Completion API, block to indicate start and end of a long running task\n- Method called if task is not completed\n\nNEXT: fail->notification, success->notification\n
  • - Task Completion API, block to indicate start and end of a long running task\n- Method called if task is not completed\n\nNEXT: fail->notification, success->notification\n
  • - Task Completion API, block to indicate start and end of a long running task\n- Method called if task is not completed\n\nNEXT: fail->notification, success->notification\n
  • - show error message if task is not completed\n\nNEXT: problems encountered\n
  • 1 & 2) this level of accuracy may not be good enough to notify users of arrival time. \n\n3) sometimes this causes late notifications, or notifications from a stop further away popup only when you reach another monitored bus stop\n\n4) entering/exiting region only works for ‘Region Monitoring in iPhone 4’. To solve this, I have the app remembers the last location so it can find out if it is entering/exiting a region.\n\nNEXT: more problems encountered\n\n\n\n
  • - affects both background location API\n\n1) create a new project to test background location - then rewrote sg buses to make it more efficient\n\n2) if users reinstall the app, the regions are monitored immediately, but the app does not the old data to make use of the monitored regions\n- the reason why I have not integrated for iPhone 4 yet. - solved by deleting the app and resetting locations for all apps\n\n3) if arrow disappears, it means background location is not working. throughout testing, I must have done quite a lot things to mess it up. Not sure of the problem, but solved by reset \n\nNEXT: NO DEMO, how to debug\n
  • 1) use it to show information you need while debugging e.g. lat,lng\n\n2) have more than 2 hours commuting from CCK to buUuk office in Paya Lebar\n\nNEXT: making sure app works if you target 3.x\n\n
  • 1) or check that multitasking is supported\n\n2) even if an app can be compiled, does not mean that it will run fine\n- if you are building universal binary for iPhone and iPad, you may want to check if a class if available\n\nNEXT: the end, and buUuk is HIRING\n
  • 1) or check that multitasking is supported\n\n2) even if an app can be compiled, does not mean that it will run fine\n- if you are building universal binary for iPhone and iPad, you may want to check if a class if available\n\nNEXT: the end, and buUuk is HIRING\n
  • 1) or check that multitasking is supported\n\n2) even if an app can be compiled, does not mean that it will run fine\n- if you are building universal binary for iPhone and iPad, you may want to check if a class if available\n\nNEXT: the end, and buUuk is HIRING\n
  • 1) or check that multitasking is supported\n\n2) even if an app can be compiled, does not mean that it will run fine\n- if you are building universal binary for iPhone and iPad, you may want to check if a class if available\n\nNEXT: the end, and buUuk is HIRING\n
  • \n

Transcript

  • 1. Background location in iOS 4.x SG Buses V3Muh Hon Cheng twitter.com/honchengMobile Developer (iOS, Android & WP7) facebook.com/honchengbuUuk Pte Ltd honcheng@gmail.com
  • 2. SG Buses V3
  • 3. Background arrival timeSG Buses V3 • iOS 4.x features used: • Signification location changes • Task completion API • Local notification
  • 4. Background LocationUsing signification location changes • Resumes suspended applications or launches terminated applications after changing cell towers • Accuracy similar to cell positioning • Notifications may be clustered while device sleeps to prevent battery drain • Supported in iPhone 4 and iPhone 3GS
  • 5. Background LocationUsing signification location changes // enable monitoring when app exits - (void)applicationDidEnterBackground:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager startMonitoringSignificantLocationChanges]; } } // disable monitoring when app starts - (void)applicationDidBecomeActive:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager stopMonitoringSignificantLocationChanges]; } }
  • 6. Background LocationUsing signification location changes // enable monitoring when app exits - (void)applicationDidEnterBackground:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager startMonitoringSignificantLocationChanges]; } } // disable monitoring when app starts - (void)applicationDidBecomeActive:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager stopMonitoringSignificantLocationChanges]; } }
  • 7. Background LocationUsing signification location changes // enable monitoring when app exits - (void)applicationDidEnterBackground:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager startMonitoringSignificantLocationChanges]; } } // disable monitoring when app starts - (void)applicationDidBecomeActive:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager stopMonitoringSignificantLocationChanges]; } }
  • 8. Background LocationUsing signification location changes // enable monitoring when app exits - (void)applicationDidEnterBackground:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager startMonitoringSignificantLocationChanges]; } } // disable monitoring when app starts - (void)applicationDidBecomeActive:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager stopMonitoringSignificantLocationChanges]; } }
  • 9. Background LocationUsing signification location changes // enable monitoring when app exits - (void)applicationDidEnterBackground:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager startMonitoringSignificantLocationChanges]; } } // disable monitoring when app starts - (void)applicationDidBecomeActive:(UIApplication*)application { if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { [locationManager stopMonitoringSignificantLocationChanges]; } }
  • 10. Background LocationUsing signification location changes// CLLocationManager delegate, called when there is a location update- (void)locationManager:(CLLocationManager*)locationManager didUpdateToLocation: (CLLocation*)newLocation fromLocation: (CLLocation*)oldLocation{ UIApplicationState state = [UIApplication shareApplication].applicationState; if (state==UIApplicationStateInactive || state==UIApplicationStateBackground) { // location changed when application is in background } else ......}
  • 11. Background LocationUsing signification location changes// CLLocationManager delegate, called when there is a location update- (void)locationManager:(CLLocationManager*)locationManager didUpdateToLocation: (CLLocation*)newLocation fromLocation: (CLLocation*)oldLocation{ UIApplicationState state = [UIApplication shareApplication].applicationState; if (state==UIApplicationStateInactive || state==UIApplicationStateBackground) { // location changed when application is in background } else ......}
  • 12. Background LocationUsing signification location changes// CLLocationManager delegate, called when there is a location update- (void)locationManager:(CLLocationManager*)locationManager didUpdateToLocation: (CLLocation*)newLocation fromLocation: (CLLocation*)oldLocation{ UIApplicationState state = [UIApplication shareApplication].applicationState; if (state==UIApplicationStateInactive || state==UIApplicationStateBackground) { // location changed when application is in background } else ......}
  • 13. Querying bus arrival time in backgroundUsing Task Completion API // get arrival time - (void)getArrivalTimeForLocation:(id)locationInfo { UIBackgroundTaskIdentifier bgTask = [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{ [self backgroundTaskNotCompleted:locationInfo]; }]; // get bus arrival time here [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }
  • 14. Querying bus arrival time in backgroundUsing Task Completion API // get arrival time - (void)getArrivalTimeForLocation:(id)locationInfo { UIBackgroundTaskIdentifier bgTask = [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{ [self backgroundTaskNotCompleted:locationInfo]; }]; // get bus arrival time here [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }
  • 15. Querying bus arrival time in backgroundUsing Task Completion API // get arrival time - (void)getArrivalTimeForLocation:(id)locationInfo { UIBackgroundTaskIdentifier bgTask = [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{ [self backgroundTaskNotCompleted:locationInfo]; }]; // get bus arrival time here [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }
  • 16. Querying bus arrival time in backgroundUsing Task Completion API // get arrival time - (void)getArrivalTimeForLocation:(id)locationInfo { UIBackgroundTaskIdentifier bgTask = [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{ [self backgroundTaskNotCompleted:locationInfo]; }]; // get bus arrival time here [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }
  • 17. Querying bus arrival time in backgroundUsing Task Completion API // get arrival time - (void)getArrivalTimeForLocation:(id)locationInfo { UIBackgroundTaskIdentifier bgTask = [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{ [self backgroundTaskNotCompleted:locationInfo]; }]; // get bus arrival time here [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }
  • 18. Display bus arrival time in a popupUsing Local Notification // show error message if task is not completed - (void)backgroundTaskNotCompleted:(id)locationInfo { UILocalNotification localNotif = [UILocalNotification new]; .... [[UIApplication shareApplication] presentLocalNotificationNow:localNotif]; [localNotif release]; } // show arrival time - (void)backgroundTaskCompleted:(id)locationInfo { UILocalNotification localNotif = [UILocalNotification new]; .... [[UIApplication shareApplication] presentLocalNotificationNow:localNotif]; [localNotif release]; }
  • 19. Background LocationProblems encountered with Significant Location Change API • Accuracy ranges from 500m to 3km - varies for different places • Not accurate underground • Notifications get clustered and shown later than expected • Does not differentiate entering & exiting region
  • 20. Background LocationProblems encountered • App gets terminated immediately after resuming • Monitored regions using Region Monitoring API does not get removed if users delete the app - filed a bug report • Location arrow disappears when app exits even with background location enabled
  • 21. Background LocationTesting background location • Use local notification to test that background location is working • Connect iPhone to laptop and get console logs in MRT
  • 22. Targeting iOS 4.x and belowCheck that a method is available if ([UIDevice respondsToSelector:@selector(isMultitaskingSupported)]) { if ([UIDevice isMultitaskingSupported]) { ..... } }Check that a class is available Class localNotificationClass = NSClassFromString(@”UILocalNotification”); if (localNotificationClass) { id localNotification = [NSClassFromString(@”UILocalNotification”) new]; ..... }
  • 23. Targeting iOS 4.x and belowCheck that a method is available if ([UIDevice respondsToSelector:@selector(isMultitaskingSupported)]) { if ([UIDevice isMultitaskingSupported]) { ..... } }Check that a class is available Class localNotificationClass = NSClassFromString(@”UILocalNotification”); if (localNotificationClass) { id localNotification = [NSClassFromString(@”UILocalNotification”) new]; ..... }
  • 24. Targeting iOS 4.x and belowCheck that a method is available if ([UIDevice respondsToSelector:@selector(isMultitaskingSupported)]) { if ([UIDevice isMultitaskingSupported]) { ..... } }Check that a class is available Class localNotificationClass = NSClassFromString(@”UILocalNotification”); if (localNotificationClass) { id localNotification = [NSClassFromString(@”UILocalNotification”) new]; ..... }
  • 25. Targeting iOS 4.x and belowCheck that a method is available if ([UIDevice respondsToSelector:@selector(isMultitaskingSupported)]) { if ([UIDevice isMultitaskingSupported]) { ..... } }Check that a class is available Class localNotificationClass = NSClassFromString(@”UILocalNotification”); if (localNotificationClass) { id localNotification = [NSClassFromString(@”UILocalNotification”) new]; ..... }
  • 26. Targeting iOS 4.x and belowCheck that a method is available if ([UIDevice respondsToSelector:@selector(isMultitaskingSupported)]) { if ([UIDevice isMultitaskingSupported]) { ..... } }Check that a class is available Class localNotificationClass = NSClassFromString(@”UILocalNotification”); if (localNotificationClass) { id localNotification = [NSClassFromString(@”UILocalNotification”) new]; ..... }
  • 27. Thank you ...and buUuk is hiring :)Muh Hon ChengMobile Developer (iOS, Android & WP7)buUuk Pte Ltdhoncheng@gmail.comtwitter.com/honcheng