xcode 应用终止后发送本地通知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32271528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending local notifications after the app has been terminated
提问by Henry Brown
I am making an app in iOS where it will send local notifications on a timer. It works fine when the app is in background state, but does not work when it has been terminated and closed completely.
我正在 iOS 中制作一个应用程序,它将在计时器上发送本地通知。当应用程序处于后台状态时它可以正常工作,但当它被终止并完全关闭时就无法工作。
Is there anyway to still send local notifications when this has happened?
发生这种情况时是否仍然发送本地通知?
Thanks in advance.
提前致谢。
回答by Johannes
Sure it is possible, if you schedule a local notification it will fire even if you terminate the app.
当然有可能,如果您安排本地通知,即使您终止应用程序它也会触发。
UILocalNotification *_localNotification = [[UILocalNotification alloc] init];
_localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:_value];
_localNotification.timeZone = [NSTimeZone defaultTimeZone];
_localNotification.alertBody = @"Beep... Beep... Beep...";
_localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]scheduleLocalNotification:_localNotification];
... works like a charm for me.
...对我来说就像一种魅力。
回答by picciano
The local notification can be delivered when the app is terminated or closed, but they must be scheduled when the app is running. You can set the fireDate
for a notification in the future, schedule it, and it will be delivered whether or not the app is running.
本地通知可以在应用终止或关闭时发送,但必须在应用运行时进行调度。您可以fireDate
为将来的通知设置,安排它,无论应用程序是否正在运行,它都会被传递。