应用运行时(FOREGROUND)didReceiveRemoteNotification未运行 [英] didReceiveRemoteNotification is not running when app is running (FOREGROUND)

查看:82
本文介绍了应用运行时(FOREGROUND)didReceiveRemoteNotification未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况.我的快速ios应用已连接到Cloudkit.如果该应用未运行(后台状态),则每次我都会收到通知徽章并发出警报! 如果该应用程序正在运行,则不会收到任何通知!我知道它没有击中遥控器,因为我这样做是: 1.在didReceiveRemoteNotification事件中添加一个断点 2.在插入的iphone中运行xcode 3. NSLog("detected didReceiveRemoteNotification"),因此最终代码如下:

I have a strange case. My swift ios app is connected to Cloudkit. If the app is NOT running (background state), I receive my notifications badge and alert just fine, every time! If the app is running, no notifications are received! I know it is not hitting the remote because I do this: 1. Adding a breakpoint to the didReceiveRemoteNotification event 2. Running xcode in a plugged iphone 3. NSLog("detected didReceiveRemoteNotification"), so final code look like this

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
  NSLog("detected didReceiveRemoteNotification")
}

我知道错误并非来自cloudkit或APNS,因为当手机处于后台状态时,我确实会收到警报横幅和标志.

I know the error is not coming from cloudkit or from APNS because I do receive alert banner and badge when the phone is in the background state.

您能指导我针对前景状态进行正确设置吗?

Can you guide me to set this up properly for the Foreground state!?

我正在运行ios v9.3

I am running ios v9.3

更新#1 我认为文档的措辞很差.它清楚地表明,两者都是在前台运行,这正是我所关心的.但是,此修复程序比文档更准确!

UPDATE #1 I think the wording of the documentation is poor. It clearly says that both run on the foreground, which is what I cared about; nevertheless, the fix is more accurate than the documentation!

与application:didReceiveRemoteNotification:方法不同,该方法是 仅当您的应用在前台运行时才调用 当您的应用在前台运行时调用此方法,或者 背景.

Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background.

推荐答案

您实现了错误的方法.实施:

You've implemented the wrong method. Implement:

func application(_ application: UIApplication,
    didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
    fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

文档说明:

application:didReceiveRemoteNotification:方法不同,...当您的应用程序在前台或后台运行时,系统会调用此方法.

Unlike the application:didReceiveRemoteNotification: method, ... the system calls this method when your app is running in the foreground or background.

这篇关于应用运行时(FOREGROUND)didReceiveRemoteNotification未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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