why*_*yyy 4 ios firebase firebase-authentication firebase-cloud-messaging
目前正在努力应对日志中出现的以下错误:
<Error> [Firebase/Auth][I-AUT000015] The UIApplicationDelegate must handle remote notifcation for phone number authentication to work.
调用时以及此NSError对象verifyPhoneNumber:completion::
@"NSLocalizedDescription" : @"If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method."
@"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
Run Code Online (Sandbox Code Playgroud)
控制器1
...
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
...
Run Code Online (Sandbox Code Playgroud)
控制器2 - 收到APNS和FCM后OK
...
[[FIRPhoneAuthProvider provider] verifyPhoneNumber:@"+11111111"
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
// Here is where I get that error.
}];
...
Run Code Online (Sandbox Code Playgroud)
Has*_*jmi 10
你错过了在你的方法中添加这个方法 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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2861 次 |
| 最近记录: |