【问题标题】:startMonitoringSignificantLocationChanges if can terminated my appstartMonitoringSignificantLocationChanges 如果可以终止我的应用程序
【发布时间】:2012-12-05 09:15:03
【问题描述】:

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

【问题讨论】:

    标签: iphone ios


    【解决方案1】:
    1. 在 ios 6 中有一个新的地图功能,可以停止位置更新 它有助于唤醒应用以接收位置更新。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];
    }
    }
    

    【讨论】:

    • 感谢您的回答,我想知道我的问题答案是否正确。并非所有设备都使用 ios6。而且我的应用不是 voip
    • 只有 ios 6 会停止位置更新以改善电池。 ios 5 工作正常。如果不是 VOIP,您将无法启动您的应用。
    • 如果我可以在位置发生重大变化时发送本地通知?我的应用程序已关闭
    • 请检查您的位置管理器的委托处理程序是否已初始化?你遇到了什么错误?
    • 它将取消使用 [[UIApplication sharedApplication] cancelLocalNotification:_notificationAlert] 的旧通知;您可以将通知添加到数组并可以使用 nsuserdefault 保存它们,它会起作用。
    猜你喜欢
    • 2016-01-26
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    相关资源
    最近更新 更多