我在註釋下面提到的行(讓data = fbResult.objectForKey(「data」)as!NSMutableArray)出現SIGABRT ABORT崩潰。我只是想通過Facebook保存用戶的分數。請注意,我無法重現此問題,並且這種情況發生在極少數設備上。我剛剛通過崩潰報告得到了這個問題。SIGUBRT ABORT在iOS上崩潰
var fbScore = 0
func getFBScore(){
if(FBSDKAccessToken.currentAccessToken() != nil){
var request = FBSDKGraphRequest(graphPath: "me/scores?fields=score", parameters: nil)
request.startWithCompletionHandler({(connection, result, error) -> Void in
if(error != nil){
println("facebook score reading failed with error \(error)")
} else {
println("facebook score reading result \(result)")
let fbResult = result as! NSDictionary
//crash on below line
let data = fbResult.objectForKey("data") as! NSMutableArray
if(data.count == 0){
self.postFBScore(0)
} else {
if let mScore = data[0].objectForKey("score") as? Int{
self.fbScore = mScore
println("facebook score is \(self.fbScore)")
} else{
self.postFBScore(0)
}
}
}
})
}
}
這是我得到的崩潰報告。
Thread : Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0x00000001954db270 __pthread_kill + 8 1 libsystem_pthread.dylib 0x0000000195579160 pthread_kill + 112 2 libsystem_c.dylib 0x0000000195452aa0 abort + 112 3 libswiftCore.dylib 0x0000000100a6dd80 swift::fatalError(char const*, ...) + 182 4 libswiftCore.dylib 0x0000000100a4aefc swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) + 70 5 libswiftCore.dylib 0x0000000100a4af80 swift::swift_dynamicCastFailure(swift::Metadata const*, swift::Metadata const*, char const*) + 130 6 libswiftCore.dylib 0x0000000100a6f6dc swift_dynamicCastObjCClassUnconditional + 72 7 MY_APP 0x00000001000e5c70 MY_APP.GameScene.(getFBScore (MY_APP.GameScene) ->() ->()).(closure #1) (GameScene.swift:1600) 8 MY_APP 0x00000001003d6ea4 -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] (FBSDKGraphRequestMetadata.m:48) 9 MY_APP 0x00000001003ddef0 __82-[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:]_block_invoke394 (FBSDKGraphRequestConnection.m:719) 10 MY_APP 0x00000001003ddca0 -[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:] (FBSDKGraphRequestConnection.m:768) 11 MY_APP 0x00000001003dd768 __64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke (FBSDKGraphRequestConnection.m:697) 12 CoreFoundation 0x00000001832b0d48 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 132 13 CoreFoundation 0x00000001832b0c2c -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 312 14 MY_APP 0x00000001003dd500 -[FBSDKGraphRequestConnection completeWithResults:networkError:] (FBSDKGraphRequestConnection.m:679) 15 MY_APP 0x00000001003dc950 -[FBSDKGraphRequestConnection completeFBSDKURLConnectionWithResponse:data:networkError:] (FBSDKGraphRequestConnection.m:544) 16 MY_APP 0x00000001003da910 __36-[FBSDKGraphRequestConnection start]_block_invoke_2 (FBSDKGraphRequestConnection.m:188) 17 MY_APP 0x00000001003d76ec -[FBSDKURLConnection invokeHandler:error:response:responseData:] (FBSDKURLConnection.m:104) 18 MY_APP 0x00000001003d7644 -[FBSDKURLConnection logAndInvokeHandler:response:responseData:] (FBSDKURLConnection.m:96) 19 MY_APP 0x00000001003d7a28 -[FBSDKURLConnection connectionDidFinishLoading:] (FBSDKURLConnection.m:143) 20 CFNetwork 0x0000000182e391e8 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 80 21 CFNetwork 0x0000000182e39178 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208 22 CFNetwork 0x0000000182e392f4 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60 23 CFNetwork 0x0000000182d0bdfc ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 104 24 CFNetwork 0x0000000182dd6120 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104 25 CFNetwork 0x0000000182cf7efc RunloopBlockContext::_invoke_block(void const*, void*) + 76 26 CoreFoundation 0x000000018329c97c CFArrayApplyFunction + 68 27 CFNetwork 0x0000000182cf7da8 RunloopBlockContext::perform() + 136 28 CFNetwork 0x0000000182cf7c5c MultiplexerSource::perform() + 312 29 CFNetwork 0x0000000182cf7a88 MultiplexerSource::_perform(void*) + 68 30 CoreFoundation 0x0000000183373f8c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 31 CoreFoundation 0x0000000183373230 __CFRunLoopDoSources0 + 264 32 CoreFoundation 0x00000001833712e0 __CFRunLoopRun + 712 33 CoreFoundation 0x000000018329cf74 CFRunLoopRunSpecific + 396 34 GraphicsServices 0x000000018cba76fc GSEventRunModal + 168 35 UIKit 0x0000000187e9ed94 UIApplicationMain + 1488 36 MY_APP 0x00000001000f6c58 main (AppDelegate.swift:16) 37 libdyld.dylib 0x00000001953c2a08 start + 4
當我嘗試在控制檯上打印fbResult時,這就是我所得到的結果。
{ 數據=( { 得分= 41; 用戶= { ID = 10206371034343540; 名稱= 「羅希特夏爾戈亞爾」; }; } ); }
您正在將fbResult.objectForKey(「data」)向下轉換爲NSMutableArray。 如果已知字典關鍵字只包含NSMutableArray實例,則可以使用強制類型轉換運算符(與!)一起直接下載並解包爲非可選的NSMutableArray: 您是否可以在控制檯中打印fbResult並共享? –
'data'鍵是一個數組?在這裏打印結果控制檯或長時間使用pastie。 –
@ Prabhu.Somasundaram這是它。 { 數據=( { 得分= 41; 用戶= { ID = 10206371034343540; 名稱= 「羅希特夏爾戈亞爾」; }; } ); } –