2

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

  1. 对于一个普通的应用,如果应用进入后台,10分钟后,系统可以杀死应用。如果我使用startMonitoringSignificantLocationChanges,当我进入后台两个小时,我的应用没有终止,因为我点击图标,应用会进入最后一个退出页面。如果应用程序被杀死,当您单击图标时,您将首先看到默认页面。所以我的问题是使用 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 位置键”等等,如果我在上面的代码中发送本地通知,用户是否会收到?

4

1 回答 1

2
  1. 在 ios 6 中有一个新的地图功能,它可以停止位置更新它有助于唤醒应用程序以接收位置更新。关联

    locationManager.pausesLocationUpdatesAutomatically

另请参阅所有其他人

  1. 如果它的VOIP,您的应用程序可以在设备启动时启动。看到这个苹果文档

对于本地通知添加到

 - (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];
}
}
于 2012-12-05T13:50:25.170 回答