我想在收到通知时调用函数,即使我的应用程序处于后台
我在stackoverflow上找到了很多问题/答案
但在我身上却不是。所以我会解释我所做的一切
我已激活后台模式
here
我的信息。plist很好
here
在我的didFinishLaunchingWithOption中
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Badge | .Sound | .Alert, categories: nil))
application.registerForRemoteNotifications()
我有
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println("NOTIFICATION 4");
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
println("NOTIFICATION FETCH");
}
但我发送通知时看不到日志
我的通知是这样发送的
{ deviceToken: XXXXX,
expiration: 1442225011,
identifier: 0,
payload:
{ 'content-available': '1',
aps: { badge: 0, alert: 'Hello' } } }
我不知道该做什么……我真的无法收到此通知,什么都没有发生(我收到横幅,但没有调用我的功能)
非常感谢