iOS本地通知 - 在后台进行回调 [英] iOS Local Notification - Callback when in Background

查看:144
本文介绍了iOS本地通知 - 在后台进行回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:
我的iOS应用程序使用本地通知
我安排本地通知,然后在通知触发时通过 didRecieveLocalNotifications 收到回电。

当应用程序位于前景时,此功能正常但是当应用程序进入后台时,我会获得iOS通知但没有回电

This works fine when the app is in foreground however when the App goes in the background I get the iOS notification but no call back.

我的问题:
当应用程序处于后台时,如何从iOS获得回调。

My Question: How can I get a callback from iOS when the app is in background.

这是回调代码 -

- (void)application:(UIApplication *)application didReceiveLocalNotification:    (UILocalNotification *)notification
{

    //call your method that you want to do something in your app
    NSLog (@"Received Notification");
    [UIApplication sharedApplication].applicationIconBadgeNumber = 1;
    [myRootController HandleLocalNotifications:notification];

}


推荐答案

你是描述应用程序:didReceiveLocalNotification:。这在iOS 10中已弃用。您应该更新到UserNotification框架。

You are describing application:didReceiveLocalNotification:. This is deprecated in iOS 10. You should be updating to the UserNotification framework.

现在。

如果你的应用程序是最前面的,用户没有得到警报。相反,获取应用程序:didReceiveLocalNotification:

If you app is frontmost, the user gets no alert. Instead, you get application:didReceiveLocalNotification:.

如果您的应用是不是最前面的,用户会收到提醒。因此,您执行获取应用程序:didReceiveLocalNotification:,因为通知已触发。但是,如果用户收到通知并通过点击通知提醒召唤您的应用,则执行获取。如果用户这样做,即使在后台也会得到 application:didReceiveLocalNotification:

If your app is not frontmost, the user gets an alert. Therefore, you do not get application:didReceiveLocalNotification: because the notification fired. But you do get it if the user received the notification and summoned your app by tapping the notification alert. If the user does that, you will get application:didReceiveLocalNotification: even in the background.

如果您的应用是但是,在后台终止,你将得到 application:didFinishLaunchingWithOptions:(你可以检查选项来了解你因为通知而被启动了。

If your app was terminated in the background, however, you will get application:didFinishLaunchingWithOptions: (and you can check the options to learn that you're being launched because of the notification).

如果你的应用程序在后台运行或没有运行,那么用户点按通知和召唤你的应用程序,你将什么也得不到,并且无法知道通知已被解雇。这是因为通知不是您的权益,而是向用户发送邮件的方式。 (听起来,从您的问题来看,好像您可能滥用本地通知作为向自己发送消息的一种方式。这不是它们的用途。)

If your app was in the background or not running, and the user does not tap the notification and summon your app, you will get nothing at all and will have no way to know that the notification fired. This is because notifications are not for your benefit but are a way of sending a message to the user. (It sounds, from your question, as if you may be misusing local notifications as a way of sending a message to yourself. That is not what they are for.)

这篇关于iOS本地通知 - 在后台进行回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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