2

i am want to use startMonitoringSignificantLocationChanges in my app,but i have some question,i hope get some help:

  1. 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?

  2. 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?

pengwang
  • 19,536
  • 34
  • 119
  • 168

1 Answers1

2
  1. 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.

  1. Your app can start on device boot if its VOIP. see this apple doc

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];
}
}
Community
  • 1
  • 1
HDdeveloper
  • 4,396
  • 6
  • 40
  • 65
  • thank you for your answer,i want to know if my question answer is correct.and not all device use ios6.and my app is not voip – pengwang Dec 05 '12 at 13:52
  • 1
    only ios 6 stops location updates for improving battery. ios 5 works fine. You can't launch your app if its not VOIP. – HDdeveloper Dec 05 '12 at 13:55
  • if i can send a local notification when significant location change ?my app is closed – pengwang Dec 05 '12 at 13:58
  • 1
    please check whether the delegate handler of your location manager is initialised? What error are you getting? – HDdeveloper Dec 05 '12 at 14:01
  • from your modify code your mean if all delete and so on are correct,if my app is closed,when significant location change it send the notication,am i right? – pengwang Dec 05 '12 at 14:05
  • 1
    it will cancel the old notification on using [[UIApplication sharedApplication] cancelLocalNotification:_notificationAlert]; You can add notification to array and can save them using nsuserdefault, it will work. – HDdeveloper Dec 05 '12 at 14:11