申请终止的本地通知 [英] Local notification on application termination

查看:110
本文介绍了申请终止的本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个如果被终止则无法运行的应用程序。它有一些后台任务。如果应用程序终止,我想显示本地通知。有些应用程序执行此操作意味着这是可行的。但我无法找到方法。

I am working on an application which will not work if terminated. It has some background tasks. I want to show a local notification if the app is terminated. There are applications which do this which means this is doable. But I am not able to find out a way.

我试图在applicationWillTerminate:appdelegate的方法中设置本地通知,并添加了应用终止的通知在我的viewcontroller中,当app实际终止时,没有任何方法被调用。

I have tried to set up a local notification in applicationWillTerminate: method of appdelegate as well as added a notification of app termination in my viewcontroller but none of the methods get called when app is actually terminated.

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"terminated");
    UIApplication * app = [UIApplication sharedApplication];
    NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
    UILocalNotification *alarm = [[UILocalNotification alloc] init] ;
    if (alarm) {
        alarm.fireDate = [NSDate date];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.alertBody = @"This app does not work if terminated";
        alarm.alertAction = @"Open";
        [app scheduleLocalNotification:alarm];
    }

    [app presentLocalNotificationNow:alarm];
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

任何帮助都会很棒。

提前致谢!!!

推荐答案

当你的应用程序被终止时,你不会收到任何通知暂停在后台。

You will not receive any notice when it gets terminated, when your app is suspended in the background.

iOS将为您的应用程序进度发送kill -9信号,您的应用程序刚刚被杀死,这与用户发生的情况相同从快速启动托盘中杀死您的应用。

iOS will send a kill -9 signal for your apps progress and you app is just killed, this is the same thing that happens when the user kills your app from the quicklaunch tray.

来自 Apple文档


即使您开发了应用程序使用iOS SDK 4及更高版本,您仍然必须准备
,以便在没有任何通知的情况下杀死您的应用。
用户可以使用多任务UI显式杀死应用程序。此外,如果内存受限制,
,系统可能会从
内存中删除应用程序以腾出更多空间。暂停的应用程序不会收到
终止的通知,但如果您的应用程序当前正在后台运行
状态(并且未暂停),系统将调用您的应用程序委托的
applicationWillTerminate:方法。您的应用无法通过此方法请求
请求额外的后台执行时间。

Even if you develop your app using iOS SDK 4 and later, you must still be prepared for your app to be killed without any notification. The user can kill apps explicitly using the multitasking UI. In addition, if memory becomes constrained, the system might remove apps from memory to make more room. Suspended apps are not notified of termination but if your app is currently running in the background state (and not suspended), the system calls the applicationWillTerminate: method of your app delegate. Your app cannot request additional background execution time from this method.

这篇关于申请终止的本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆