【问题标题】:Understanding app background launch behavior了解应用后台启动行为
【发布时间】:2016-09-19 05:42:46
【问题描述】:

在苹果文档Understanding When Your App Gets Launched into the Background

支持后台执行的应用程序可能会被系统重新启动 处理传入事件...

我正在做region monitoring,当我得到它时,我正在弹出一个UILocalNotification,但是当我点击UILocalNotification 时,我的应用程序didReceiveLocalNotification 被调用。可能是因为我的应用是在后台启动的。

我做的第二件事是我没有点击 UILocalNotification 并离开了几分钟,这意味着我的应用程序将被 iOS 终止。我拖动通知中心,然后点击UILocalNotification 仍然是我的应用输入didReceiveLocalNotification

我期望应用程序现在在延迟UILocalNotification点击时启动的行为必须输入此方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

        if (notification) 
        {
            NSLog(@"notification caused app to launch, alert body = %@", notification.alertBody);
            // do what ever action you want to do
            // you could just copy the code from "didReceiveLocalNotification" and paste it here
        }

        return YES;
    }

究竟发生了什么,可以请任何人详细解释一下吗?

即使在我点击UILocalNotification 应用程序延迟之后也无法进入

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

【问题讨论】:

    标签: ios objective-c core-location uilocalnotification appdelegate


    【解决方案1】:

    您的应用在几分钟不活动后并未终止。
    它变为空闲状态,仅在需要内存时才终止。
    请记住,它是为了在后台处理区域更改而启动的,并且它首先发送通知,因此它在此阶段驻留在设备内存中。
    尝试使用多任务界面显式退出它或启动多个内存消耗应用程序(游戏通常会这样做)以强制它退出。
    在后台等待几分钟不会让它终止。

    【讨论】:

    • 好的,我试试,谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多