我是一名网络开发人员,我是第一次构建React Native应用程序。 该应用程序正在工作和编译,直到我添加了对推送通知的FCM支持。
我使用CocoaPods跟踪了React-Native-FCM的所有说明。
现在,通过内置xCode失败并出现此错误:
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
我的AppDelegate文件如下所示:
// // Copyright (c) 2016 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "AppDelegate.h" #import "RCTBundleURLProvider.h" #import "RCTRootView.h" #import "RNFIRMessaging.h" // Copied from Apple's header in case it is missing in some cases (e.g. pre-Xcode 8 builds). #ifndef NSFoundationVersionNumber_iOS_9_x_Max #define NSFoundationVersionNumber_iOS_9_x_Max 1299 #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"Mamaz" initialProperties:nil launchOptions:launchOptions]; 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]; [FIRApp configure]; #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; #endif return YES; } #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.request.content.userInfo]; if([[notification.request.content.userInfo valueForKey:@"show_in_foreground"] isEqual:@YES]){ completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound); }else{ completionHandler(UNNotificationPresentationOptionNone); } } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { NSDictionary* userInfo = [[NSMutableDictionary alloc] initWithDictionary: response.notification.request.content.userInfo]; [userInfo setValue:@YES forKey:@"opened_from_tray"]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo]; } #else //You can skip this method if you don't want to use local notification -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.userInfo]; } #endif - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo]; completionHandler(UIBackgroundFetchResultNoData); } @end
我的PodFile是这样的:
target 'App' do use_frameworks! # Pods for App pod 'Firebase/Core' pod 'Firebase/Messaging' target 'AppTests' do inherit! :search_paths # Pods for testing end end
有没有人遇到过这样的问题?我甚至无法理解导致它的原因(因为错误信息不是很具描述性)
答案 0 :(得分:1)
使用通用错误消息,您可能只会获得通用答案。
尝试:
a)删除#define NSFoundationVersionNumber_iOS_9_x_Max 1299
以获得提示,就像您的工具链是否正确一样。
b)关闭Xcode 8.1(完全关闭,与cmd + q一样),删除DerivedData文件夹,清空垃圾箱。并且只在最后一步之后重新打开Xcode,才能正确地重新构建缓存。
c)确保您使用的是CocoaPods 1.1.1。毫无疑问,您也可以更新其他工具。示例:sudo gem update -n /usr/local/bin --system && sudo gem update -n /usr/local/bin
d)use_frameworks!
之前target
,这就是我们通常的做法
e)pod deintegrate && pod install
,正确重新整合豆荚
f)最后,克隆你的项目,并尝试从克隆的repo构建:如果它工作,删除旧的repo并使用新的:)。如果它仍然失败,那么您可以开始删除代码段以尝试获取具有最小测试用例的配置,您可以在CocoaPods问题跟踪器上进行共享以进行调查。