Reputation: 19966
i am want to use startMonitoringSignificantLocationChanges in my app,but i have some question,i hope get some help:
for a common app if app enter background,after 10mins ,system can kill the app.if i used startMonitoringSignificantLocationChanges ,when i enter background two hours,my app not terminated,because i click the icon,app will enter the last quit page 。if app is killed,when you click the icon you will first see the default page. so my question is use startMonitoringSignificantLocationChanges my app not killed by system after enter background 10 mins?
if i close mobile,and restart the mobile,when significant location change,my app if can be activate ,i look apple develop document it answer yes.so i test:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if([CLLocationManager significantLocationChangeMonitoringAvailable]){
[self log:@"sigAvailable=YES"];
}
// Override point for customizatio-n after application launch.
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
// create a new manager and start checking for sig changes
[self log:@"didFinishLaunchingWithOptions location key"];
m_locManager = [[CLLocationManager alloc] init];
[self log:@"didFinishLaunchingWithOptions created manager"];
m_locManager.delegate = self;
[self log:@"didFinishLaunchingWithOptions set delegate"];
[m_locManager startMonitoringSignificantLocationChanges];
[self log:@"didFinishLaunchingWithOptions monitoring sig changes"];
// do send local notification
return YES;
}
[self log:@"didFinishLaunchingWithOptions"];
return YES;
}
my question: when restart mobile and local notification,above code is run and log "didFinishLaunchingWithOptions location key" and so on,if i send local notification at the above code, if user will receive?
Upvotes: 3
Views: 2114
Reputation: 4404
in ios 6 there is new feature for maps, which stops location updates It helps to wake app to recieve location updates.link
locationManager.pausesLocationUpdatesAutomatically
Also see all others.
for local notification add to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// creating local notification
Class cls = NSClassFromString(@"UILocalNotification");
if (cls)
{
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
NSLog(@"notification text:%@",reminderText);
// [viewController._msgTextView setText:reminderText];
}
}
application.applicationIconBadgeNumber = 0;
and you can handle them in
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"application:didReceiveLocalNotification:");
}
you can schedule your local notification in
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = notifyDate;
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = AlertMsg;
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
notif.alertAction = @"Show me";
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
}
Upvotes: 2