简体   繁体   English

当应用程序在后台时推送通知

[英]Push notification when app in background

Suppose a scenario: there are 2 users User A and User B. User A sends a push notification to User B but at that time the app was in background at User B's side. 假设有一个场景:用户A和用户B有2个用户。用户A向用户B发送推送通知,但那时该应用程序在用户B一侧处于后台。 Now the problem is User B does not receive notification because the app was in background but receives as soon as the app is bought to foreground again. 现在的问题是,用户B由于该应用程序处于后台状态而没有收到通知,但是一旦该应用程序再次被购买到前台,它就会收到通知。 Is there any way around which enables User B to get notification in the background state as well. 是否有任何方法可以使用户B在后台状态下获得通知。 Also if the Alert Style for the application is configured by the user to be "None" in the Settings app of the device, could this prevent him from receiving the notifications when app is in background.? 另外,如果用户在设备的“设置”应用程序中将应用程序的警报样式配置为“无”,是否可以防止他在应用程序处于后台时收到通知?

Thanks in advance!! 提前致谢!!

If the user disables alert notifications , he won't receive such alerts . 如果用户禁用警报通知,他将不会收到此类警报。 Otherwise he will receive the alert immediately even when the app is not running . 否则,即使该应用未运行,他也将立即收到警报。

what I understand from your question you want to run some code when notification received in background mode... 我从您的问题中了解到,您想在后台模式下收到通知时运行一些代码...

first in your target menu->capabilities ->on the background mode 首先在目标菜单中->功能->在后台模式下 在此处输入图片说明

then inside your AppDelegate add your code under the method which will fire when app is in background mode 然后在您的AppDelegate内部,将方法下的代码添加到当应用程序处于后台模式时将触发的方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {}

**But remember the most important thing ** **但请记住最重要的事情**

your push notification structure must contain content_avialable = 1 您的推送通知结构必须包含content_avialable = 1

example: 例:

    {
    aps =     {
        alert =         {
            body = "new message";
            title = "I";
        };
        "content_available" = 1;
    };
    "click_action" = "GOTO_M";
    data =     {

    };
    "gcm.message_id" = ;
    "google.c.a.e" = 1;
}

This is really what push notifications are about. 这实际上就是推送通知的内容。 If you allow for the app to send you push notifications, you will receive them even when the app is in the background. 如果允许该应用程序向您发送推送通知,则即使该应用程序在后台,您也将收到它们。 I suggest you read up on how to send push notifications. 我建议您阅读有关如何发送推送通知的内容。

Another option is to let the app itself display the notification, this can still be done while the app is in the background. 另一个选择是让应用程序本身显示通知,当应用程序在后台时仍可以完成此操作。

When they set the Alert style to none and turn of notifications they will not recieve the push notifications anymore. 当他们将“警报”样式设置为“无”并打开通知时,他们将不再接收推送通知。 But then again, they shouldn't get any if they don't want to. 但是话又说回来,如果他们不想的话,他们什么也得不到。

To your second question: 关于第二个问题:

if the Alert Style for the application is configured by the user to be "None" in the Settings app of the device, could this prevent him from receiving the notifications when app is in background? 如果用户在设备的“设置”应用中将应用的警报样式配置为“无”,是否可以防止他在后台运行时收到通知?

If a user has set "None" as the Alert Style then notifications will be received but not shown. 如果用户将“无”设置为警报样式,则将收到通知,但不会显示。 However, the user can still see that push message in the notification center. 但是,用户仍然可以在通知中心看到该推送消息。 That is the phone will not display alerts on the screen. 也就是说,电话不会在屏幕上显示警报。

Now to your first question, when properly implemented Push Notifications will be received even when the app is in background. 现在,您的第一个问题是,即使应用程序处于后台,也将在正确实施推送通知时收到通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序在后台 swift 3 时的远程推送通知 - remote push Notification when app is in background swift 3 当应用程序在后台且设备被锁定时处理推送通知 - Handling push notification when app is in background and device is locked 当app在后台时,如何对接收推送通知执行操作? - how to perform action on receive push notification when app is in background? 用户在后台收到推送后手动打开应用程序时获取推送通知有效负载 - Getting push notification payload when user opens app manually after push has been received in the background 当应用程序处于后台或运行状态时,处理推送通知,而不是在应用程序终止时 - Handle push notification when app is in Background or Running state not when app is terminated 推送通知应用程序背景iOS 9 swift - push notification app background iOS 9 swift 具有应用程序背景的iOS远程推送通知 - iOS remote push notification with app background iOS应用程序在后台时不会显示推送通知。 迅速 - IOS app won't display push notification when in background. Swift 当收到静默推送通知并且应用程序在后台,iOS中运行时,执行几行代码 - Execute few lines of code when received silent push notification and app is running in background, ios 在应用未运行时推送通知数据? - Push notification data when app is not running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM