2016-11-26 65 views
2

我是一名Web開發人員,我第一次構建了一個React Native應用程序。 該應用程序正在工作並編譯,直到我添加了對推送通知的FCM支持。React本機iOS構建失敗「無法執行命令:分割錯誤:11」

我遵循使用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 

有任何人遇到過這樣的問題?我什至不明白是什麼原因造成的(因爲錯誤信息不是很具描述性)

回答

1

有了一般性的錯誤信息,你可能會得到一般性的答案。

嘗試:

一)刪除#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)最後,克隆你的項目,並嘗試從建築克隆的回購:如果有效,刪除舊的回購並使用新的回購:)。如果它仍然失敗,那麼你可以開始刪除代碼片段,嘗試使用一個最小的測試用例來獲得配置,然後你可以在CocoaPods問題跟蹤器上共享該調查用於調查。

+0

這實際上是一個很好的答案,我不得不做所有的建議,但它的工作,謝謝! –

相關問題