【发布时间】:2015-02-26 22:20:42
【问题描述】:
我一直在尝试实现获取完成块,但没有成功。每当我发送 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.
不确定我是否在这里实现了正确的语法
【问题讨论】:
-
去掉println或者改成NSLog,然后重试。如果这不起作用,则将completionHandler包装在一个调度块中并将其提交到某个后台队列(不是主线程),因此在此方法返回之后调用它。
-
@DavidH 当我将
println替换为NSLog时,我不再看到警告。谢谢!