目前正在努力应对日志中出现的以下错误:
<错误> [Firebase / Auth] [I-AUT000015] UIApplicationDelegate必须处理远程通知才能使电话号码认证正常工作.
以及调用verifyPhoneNumber时的此NSError对象:completion ::
@“NSLocalizedDescription”:@“如果禁用了app delegate swizzling,则需要将UIApplicationDelegate收到的远程通知转发给FIRAuth的canHandleNotificaton:方法.”
@“error_name”:@“ERROR_NOTIFICATION_NOT_FORWARDED”
任何人都知道这是关于什么以及如何解决它?
我正在使用XCode 8.3.3,Firebase 4.0.0,我已经关闭了swizzling,我已经确认我成功注册了APNS(我看到令牌)和FCM(我也看到了这一点).
我在文档和iOS云消息github sample repo中都使用了示例代码.
在尝试将Firebase集成到同一个项目之前,我让Digits手机验证工作完美无缺,并且推送来自AWS SNS和Onesignal的通知.
与Firebase相关的部分的相关代码:
AppDelegate中
+ (void)initialize { FIROptions *firOptions = [[FIROptions alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"some-plist-name" ofType:@"plist"]]; [FIRApp configureWithOptions:firOptions]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRMessaging messaging].delegate = self; [FIRMessaging messaging].shouldEstablishDirectChannel = YES; [UNUserNotificationCenter currentNotificationCenter].delegate = self; // do some other setup stuff here ... return YES; } #pragma mark - FIRMessagingDelegate - (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull Nsstring *)fcmToken { // I get an fcmToken here as expected and notify the the relevant controller(s) } - (void)messaging:(nonnull FIRMessaging *)messaging didReceiveMessage:(nonnull FIRMessagingRemoteMessage *)remoteMessage { } #pragma mark - UNUserNotificationCenterDelegate - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationoptions options))completionHandler { NSDictionary *userInfo = notification.request.content.userInfo; [[FIRAuth auth] canHandleNotification:userInfo]; completionHandler(UNNotificationPresentationoptionNone); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler { completionHandler(); } #pragma mark - Notifications - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDevicetoken:(NSData*)devicetoken { FIRMessagingAPNSTokenType tokenType = FIRMessagingAPNSTokenTypeProd; #if DEBUG && !TESTFLIGHT tokenType = FIRMessagingAPNSTokenTypeSandBox; #endif [[FIRMessaging messaging] setAPNSToken:devicetoken type:tokenType]; } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [[FIRAuth auth] canHandleNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [[FIRAuth auth] canHandleNotification:userInfo]; } - (void)application:(UIApplication *) application handleActionWithIdentifier:(Nsstring *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler:(void (^)())completionHandler { completionHandler(); } @end
控制器1
... UNAuthorizationoptions authOptions = UNAuthorizationoptionAlert | UNAuthorizationoptionSound | UNAuthorizationoptionBadge; [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted,NSError * _Nullable error) { }]; [[UIApplication sharedApplication] registerForRemoteNotifications]; ...
控制器2 – 收到APNS和FCM后OK
... [[FIRPhoneAuthProvider provider] verifyPhoneNumber:@"+11111111" completion:^(Nsstring * _Nullable verificationID,NSError * _Nullable error) { // Here is where I get that error. }]; ...
解决方法
您错过了在AppDelegate中添加此方法
func application(_ application: UIApplication,didReceiveRemoteNotification notification: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if Auth.auth().canHandleNotification(notification) { completionHandler(.noData) return } // This notification is not auth related,developer should handle it. handleNotification(notification) }