jjzjj

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

coder 2024-01-20 原文

我想在我的应用程序中使用 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 location key”等,如果我用上面的代码发送本地通知,用户是否会收到?

最佳答案

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

    locationManager.pausesLocationUpdatesAutomatically

另见 all others

  1. 如果是 VOIP,您的应用可以在设备启动时启动。 看到这个 apple doc

对于本地通知添加到

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

关于iphone - startMonitoringSignificantLocationChanges 如果可以终止我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13719697/

有关iphone - startMonitoringSignificantLocationChanges 如果可以终止我的应用程序的更多相关文章

随机推荐