在iOS swift上SIGABRT ABORT崩溃

时间:2015-08-28 11:53:06

标签: ios swift facebook-ios-sdk

我在注释下面提到的行中遇到SIGABRT ABORT崩溃(让data = fbResult.objectForKey(“data”)为!NSMutableArray)。我只是想让用户的分数保存在Facebook上。请注意,我无法重现此问题,这种情况在极少数设备上发生。我刚刚通过崩溃报告得到了这个问题。

<script>window.jcepopup.create();</script>

这是我的崩溃报告。


    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时,这就是我得到的。

  

{       data =(                   {               得分= 41;               user = {                   id = 10206371034343540;                   name =“Rohit Goyal”;               };           }       ); }

2 个答案:

答案 0 :(得分:1)

由于此行有例外:

let data = fbResult.objectForKey("data") as! NSMutableArray

鉴于Swift是一种强类型和静态类型的语言,唯一可能的错误原因是使用!运算符将对象强制转换为类型NSMutableArray。因此,如果您知道绑定到键data的值是一个数组,那么您应该尝试将其强制转换为非可变数组:

let data = fbResult.objectForKey("data") as! NSArray

答案 1 :(得分:0)

尝试将其替换为:

当前

let data = fbResult.objectForKey("data") as! NSMutableArray

let data = fbResult.objectForKey("data").mutablecopy() as! NSMutableArray