目前正在努力解决日志中显示的以下错误:
Currently struggling with the following error showing up in logs:
<代码><错误>[Firebase/Auth][I-AUT000015] UIApplicationDelegate 必须处理远程通知才能进行电话号码身份验证.
以及调用 verifyPhoneNumber:completion:
时的这个 NSError 对象:
as well as this NSError object when calling verifyPhoneNumber: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(我也看到了这个).
I am using XCode 8.3.3, Firebase 4.0.0, I've switched OFF swizzling, and I already confirmed that I successfully register both for APNS (I see the token) and for FCM (I see this as well).
我在文档和 iOS 云消息 github 示例 repo 中都使用了示例代码.
I used the sample code both in documentation and in the iOS cloud message github sample repo.
在尝试将 Firebase 集成到同一个项目中之前,我让 Digits 电话身份验证工作完美无缺,并且推送通知来自 AWS SNS 和 OneSignal.
Before trying to integrate Firebase in the same project, I had Digits phone auth working flawlessly, and push notifications coming in both from AWS SNS and OneSignal.
Firebase 相关部分的相关代码:
Relevant code for Firebase-related parts:
AppDelegate
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 后
Controller 2 - after receiving APNS and 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)
}
这篇关于Firebase Phone 身份验证无法接收远程通知注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!