diff --git a/ShenQi/AppDelegate.m b/ShenQi/AppDelegate.m index 03cf2bd..d43e60c 100644 --- a/ShenQi/AppDelegate.m +++ b/ShenQi/AppDelegate.m @@ -172,6 +172,18 @@ }]; NSLog(@"APNSToken = %@",[FIRMessaging messaging].APNSToken); + + [[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) { + if (error) { + NSLog(@"FCM Token 生成失败:%@", error.localizedDescription); + // 常见错误: + // - "Unable to resolve host":网络问题或 Firebase 服务器连接失败 + // - "Invalid project number":GoogleService-Info.plist 配置错误 + } else { + NSLog(@"FCM Token:%@", token); + // 验证 Token 有效性:在 Firebase 控制台用该 Token 发送测试消息 + } + }]; } } @@ -180,6 +192,11 @@ return UIInterfaceOrientationMaskAll; } +// 注册推送失败的回调 +- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + NSLog(@"推送注册失败:%@", error.localizedDescription); +} + - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken { NSLog(@"FCM registration token: %@", fcmToken); @@ -210,6 +227,8 @@ -(void)processWithNoti:(NSDictionary *)userInfo { + + NSLog(@"Received the push notification"); NSString *message = [userInfo objectForKey:@"message"]; NSData *jsonData = [message dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *messageNotiDic = nil; diff --git a/ShenQi/MainOldViewController.m b/ShenQi/MainOldViewController.m index 4d3709f..f602ff8 100644 --- a/ShenQi/MainOldViewController.m +++ b/ShenQi/MainOldViewController.m @@ -42,7 +42,7 @@ [super viewDidLayoutSubviews]; UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.lastObject.windowScene.statusBarManager; - _webView.frame = CGRectMake(0, statusBarManager.statusBarFrame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-self.view.safeAreaInsets.bottom); + _webView.frame = CGRectMake(0, statusBarManager.statusBarFrame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-self.view.safeAreaInsets.bottom-statusBarManager.statusBarFrame.size.height); } - (void)viewDidLoad { @@ -54,11 +54,10 @@ wkWebConfig.preferences.javaScriptCanOpenWindowsAutomatically = YES; _wkUController = [[WKUserContentController alloc] init]; - wkWebConfig.userContentController = _wkUController; UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.lastObject.windowScene.statusBarManager; - _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, statusBarManager.statusBarFrame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-self.view.safeAreaInsets.bottom) configuration:wkWebConfig]; + _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, statusBarManager.statusBarFrame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-self.view.safeAreaInsets.bottom-statusBarManager.statusBarFrame.size.height) configuration:wkWebConfig]; _webView.UIDelegate = self; _webView.navigationDelegate = self; [self.view addSubview:_webView];