startMonitoringSignificantLocationChanges如果可以终止我的应用程序

时间:2012-12-05 09:15:04

标签: iphone ios

我想在我的应用中使用startMonitoringSignificantLocationChanges,但我有一些问题,希望得到一些帮助:

  1. 对于一个常见的应用程序,如果应用程序进入后台,10分钟后,系统可以杀死app.if我使用startMonitoringSignificantLocationChanges,当我进入后台两小时,我的应用程序没有终止,因为我点击图标,应用程序将进入最后一个退出页面.if应用程序被杀死,当您单击该图标时,您将首先看到默认页面。所以我的问题是使用startMonitoringSignificantLocationChanges我的应用程序在进入后台10分钟后没有被系统杀死?

  2. 如果我关闭手机,并重新启动手机,当重要的位置更改时,我的应用程序如果可以激活,我看苹果开发文档它回答是。所以我测试:

    - (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;
       }
    

    我的问题:当重启移动和本地通知时,运行上面的代码并记录“didFinishLaunchingWithOptions location key”等等,如果我在上面的代码发送本地通知,如果用户会收到?

1 个答案:

答案 0 :(得分:2)

    ios 6中的
  1. 地图有新功能,可以停止位置更新 它有助于唤醒应用以接收位置更新。link

    locationManager.pausesLocationUpdatesAutomatically

  2. 另见all others

    1. 您的应用可以在设备启动时启动VOIP。 见apple doc
    2. 将本地通知添加到

       - (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;
      

      你可以在

      中处理它们
      - (void)application:(UIApplication *)application
      didReceiveLocalNotification:(UILocalNotification *)notification
      {
          NSLog(@"application:didReceiveLocalNotification:");
      }
      

      您可以在

      中安排本地通知
      -(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];
      }
      }