本文介绍了应用程序终止后发送本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS中创建一个应用程序,它会在计时器上发送本地通知。它在应用程序处于后台状态时工作正常,但在终止并完全关闭时不起作用。

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.

当发生这种情况时,仍然会发送本地通知吗?

Is there anyway to still send local notifications when this has happened?

提前致谢。

推荐答案

当然,如果您安排本地通知,即使您终止应用也会触发。

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.

这篇关于应用程序终止后发送本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 06:33