AppDelegate.m报Expected identifier or '('错误及Firebase推送不显示求助
问题修复方案
一、语法错误(Expected identifier or '(')修复
错误原因
你在didFinishLaunchingWithOptions方法中添加FIRApp初始化代码后,提前关闭了方法的大括号,导致后续代码变成了独立的无主代码块,同时重复调用了两次[FIRApp configure],触发语法报错。
修正代码
你只需要把原来的didFinishLaunchingWithOptions相关代码替换成下面的内容即可,其他代码完全不用改:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 只保留一次FIRApp初始化,放在方法最开头 if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } #if DEBUG InitializeFlipper(application); #endif RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"shopinnadmin" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; // 删掉重复的[FIRApp configure]; 避免重复初始化 return YES; }
二、推送通知无法弹出排查点
- 确认Xcode项目的
Signing & Capabilities中已经添加了Push Notifications和Background Modes能力,Background Modes勾选了Remote notifications - 确认前端代码已经调用了
PushNotificationIOS.requestPermissions()方法申请通知权限,且用户已经同意授权 - 确认Firebase控制台已经上传了正确的APNs认证密钥/证书,且Bundle ID和项目配置一致
- 测试推送时优先用真机测试,模拟器无法接收APNs远程推送
内容的提问来源于stack exchange,提问作者Official Berry
相关产品推荐
相关产品推荐

