2016-04-05 112 views
2

我有一个iOS项目,并在调试模式下,根本没有崩溃。 将应用程序发布到TestFlight时,我从Testflight界面(使用打开按钮)启动应用程序,我收到崩溃。从Testflight开始时,应用程序崩溃打开按钮

如果我从iPhone主屏幕启动应用程序,则不会崩溃。

Thread : Crashed: com.apple.main-thread 
0 AppName       0x100316b8c specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift) 
1 AppName       0x100314284 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift) 
2 UIKit       0x1863428a8 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400 
3 UIKit       0x186572094 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904 
4 UIKit       0x186576500 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 
5 UIKit       0x186573674 -[UIApplication workspaceDidEndTransaction:] + 168 
6 FrontBoardServices    0x182b237ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 
7 FrontBoardServices    0x182b23618 -[FBSSerialQueue _performNext] + 168 
8 FrontBoardServices    0x182b239c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 
9 CoreFoundation     0x181139124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 
10 CoreFoundation     0x181138bb8 __CFRunLoopDoSources0 + 540 
11 CoreFoundation     0x1811368b8 __CFRunLoopRun + 724 
12 CoreFoundation     0x181060d10 CFRunLoopRunSpecific + 384 
13 UIKit       0x18633b834 -[UIApplication _run] + 460 
14 UIKit       0x186335f70 UIApplicationMain + 204 
15 AppName       0x100316388 main (AppDelegate.swift:18) 
16 libdispatch.dylib    0x180bfe8b8 (Missing) 

编辑

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 
    Fabric.with([Crashlytics.self]) 
    log.xcodeColorsEnabled = true 
    let dateFormatter = NSDateFormatter() 
    dateFormatter.dateFormat = "HH:mm:ss.SSS" 
    dateFormatter.locale = NSLocale.currentLocale() 
    log.dateFormatter = dateFormatter 
    #if DEBUG 
     log.setup(.Debug, showLogIdentifier: false, showFunctionName: true, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, showDate: true, writeToFile: nil, fileLogLevel: nil) 
    #else 
     log.setup(.Severe, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil) 
     if let consoleLog = log.logDestination(XCGLogger.Constants.baseConsoleLogDestinationIdentifier) as? XCGConsoleLogDestination { 
     consoleLog.logQueue = XCGLogger.logQueue 
     } 
    #endif 

    application.applicationIconBadgeNumber = 0 

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.mergeChanges(_:)), name: NSManagedObjectContextDidSaveNotification, object: nil) 

    //MARK: - Notifications registration 
    remoteToken() 

    if let launchOpts = launchOptions { 
     let remoteNotification = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary 
     if let notifFrom = remoteNotification["from"] as? Int, notifType = remoteNotification["type"] as? Int { 
     let userid = notifFrom 
     let type = notifType 
     if type != MessageType.NotifyMsgType.rawValue { 
      loadingChatUserId = userid 
     }else{ 
      loadingChatUserId = nil 
     } 
     } 
    }else{ 
     loadingChatUserId = nil 
    } 

    return true 
    } 

func remoteToken() { 
    if UIApplication.sharedApplication().isRegisteredForRemoteNotifications() { 
     //iOS 8 notifications 
     UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Sound, .Alert, .Badge], categories: nil)) 
     UIApplication.sharedApplication().registerForRemoteNotifications() 
    } 
    } 
+0

检查项目本libdispatch.dylib文件 –

+0

你可能在你不想...也许张贴该文件的AppDelegate的一些代码? – aramusss

+0

好主意,我发布了didLaunchingWithOption委托代理 – Mikael

回答

2
if let launchOpts = launchOptions { 
    let remoteNotification = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary 
    if let notifFrom = remoteNotification["from"] as? Int, notifType = remoteNotification["type"] as? Int { 
    let userid = notifFrom 
    let type = notifType 
    if type != MessageType.NotifyMsgType.rawValue { 
     loadingChatUserId = userid 
    }else{ 
     loadingChatUserId = nil 
    } 
    } 
}else{ 
    loadingChatUserId = nil 
} 

这里是你的问题......你力量展开启动选项为UIApplicationLaunchOptionsRemoteNotificationKey。改为使用可选绑定。

if let launchOpts = launchOptions { 
    if let remoteNotification = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary{ 
     .... 
    } 
+0

如果我能给你200分,我会的!非常感谢。这节省了我的一天。 – lnjuanj

相关问题