2016-08-22 18:34:50.108: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-08-22 18:34:50.106 YAKKO[4269:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
2016-08-22 18:34:50.114: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-08-22 18:34:50.120: <FIRMessaging/INFO> FIRMessaging library version 1.1.1
2016-08-22 18:34:50.125: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-08-22 18:34:50.144 YAKKO[4269:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-08-22 18:34:50.188 YAKKO[4269:] <FIRAnalytics/INFO> Firebase Analytics enabled
这个问题以前就有人问过。但我仍然不知道如何解决它。通知不起作用,我唯一的线索是:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
我已经仔细检查了我上传的。p12文件是否正确。我已经进入目标->->功能->背景模式-> remote-notifications
和ON
我已经仔细检查了我的bundleID是否匹配GoogleService-Info.plist
这是我的appdelegate。swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
....
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("DEVICE TOKEN = (deviceToken)")
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
print("Message ID: (userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
func tokenRefreshNotification(notification: NSNotification) {
// NOTE: It can be nil here
let refreshedToken = FIRInstanceID.instanceID().token()
print("InstanceID token: (refreshedToken)")
connectToFcm()
}
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
print("Unable to connect with FCM. (error)")
} else {
print("Connected to FCM.")
}
}
}
我的猜测是,它应该没有最后两个方法,但我把它们放在那里(根据打印语句,它看起来不像他们正在被调用)。
我调用registerforremotenotifations:
static func registerForNoties(){
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(pushNotificationSettings)
UIApplication.sharedApplication().registerForRemoteNotifications()
}
我可以看到deviceToken打印在控制台上。但我还是遇到了FireBase的问题。还有什么我可以检查的吗?
我确实尝试构建基于Firebase/Quickstart-iOS的iOS (Swift)示例的简单应用程序,我有同样的问题:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
。
当应用程序在后台时,我无法收到通知。所以,我在这里找到了适合我的解决方案:https://github.com/firebase/quickstart-ios/issues/103
基本上,我添加了这个方法:func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Handle push from background or closed" );
print("%@", response.notification.request.content.userInfo);
}
…这行代码:
application.registerForRemoteNotifications()
显然,在Objective-C中编写的示例工作得很好,但在Swift中的示例缺少一些代码片段,并且它不像预期的那样工作…
尝试更新Firebase/Core到v3.4.4,它为我修复了意想不到的错误。否则,尽量避免调用unregisterForRemoteNotifications
。在这个调用之后,你不能再注册设备来推送通知了。此外,尝试在您的信息中将FirebaseAppDelegateProxyEnabled
设置为NO
。plist文件。我认为他们的方法swizzling有bug
调用此方法,您将获得设备令牌。我可以看到deviceToken
打印在控制台上。
dispatch_async(dispatch_get_main_queue(),
{
global.appdel.tokenRefreshNotification()
})