didReceiveRemoteNotification:fetchCompletionHandler:但是从未调用完成处理程序

时间:2015-02-26 22:20:42

标签: ios iphone swift

我一直在尝试实现获取完成块而没有运气。每当我发送一个APN时,xcode仍然会抱怨它没有实现。这是我的代码

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

    println("2. User Data", userInfo)

    completionHandler(UIBackgroundFetchResult.NewData)

}

我在xcode控制台中收到的警告就是这个

Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

不确定我是否在这里实施正确的语法

3 个答案:

答案 0 :(得分:8)

删除println或将其更改为NSLog,然后重试。最有可能是问题是由于此方法在后台而不是在主线程上发生的。 println比NSLog简单得多,NSLog是线程安全的,并且经过多年和多年的强化。

答案 1 :(得分:1)

我有一个完全相同的问题但是完全不同的解决方案。我的问题是我导入了Intercom,因此人们可以在应用内聊天,看起来它拦截了通知,didReceiveRemoteNotification从未在AppDelegate中调用过。

我终于可以不停地撞到墙上,希望这可以节省一些人的时间。

答案 2 :(得分:0)

不确定原因,但用println替换NSLog解决了这个问题。

相关问题