如何解决 GigyaSwift v1.0 中的 Pending Registration 中断

How to resolve Pending Registration interruption in GigyaSwift v1.0

我正在尝试处理 GigyaSwift V1.0 中的挂起注册中断。我可以进入待处理的注册,但我不完全确定下一步该做什么。我正在尝试显示屏幕设置,但应用程序因 SIGABRT 错误而崩溃。

这是我的代码:

    gigya.login(with: .facebook, viewController: self, completion: { (result) in

    switch result {
    case .success(let data):
        print(data)
    case .failure(let error):
        print(error)

        guard let interruption = error.interruption else {
            gigya.logout { (_) in
            }
            return }
        // Evaluate interruption.
        switch interruption {
        case .pendingRegistration(let resolver):
            gigya.showScreenSet(with: "Default-RegistrationLogin" ,
                                viewController: self,
                                params:[ "startScreen": "gigya-complete-registration-screen"],
                                completion: { (res) in


            })
            break
        default:
            break
        }

    }
    })

我想我需要将 regToken 作为参数,但我无法通过解析器访问它,因为它具有内部访问修饰符。

当我尝试在新项目中执行此操作时,由于某种原因,SIGABRT 错误更具描述性:

2019-07-25 17:19:11.273269+0800 GigyaTester[15773:243216] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__SwiftValue)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b5986fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010ab3cac5 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010b598555 +[NSException raise:format:] + 197
    3   Foundation                          0x0000000109f97b3c _writeJSONValue + 706
    4   Foundation                          0x0000000109f9ba98 ___writeJSONObject_block_invoke + 176
    5   libswiftCore.dylib                  0x000000010bc2f481 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 897
    6   libswiftCore.dylib                  0x000000010ba4f8db $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 43
    7   Foundation                          0x0000000109f9b046 _writeJSONObject + 466
    8   Foundation                          0x0000000109f9ba98 ___writeJSONObject_block_invoke + 176
    9   libswiftCore.dylib                  0x000000010bc2f481 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 897
    10  libswiftCore.dylib                  0x000000010ba4f8db $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 43
    11  Foundation                          0x0000000109f9b046 _writeJSONObject + 466
    12  Foundation                          0x0000000109f9ba98 ___writeJSONObject_block_invoke + 176
    13  libswiftCore.dylib                  0x000000010bc2f481 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 897
    14  libswiftCore.dylib                  0x000000010ba4f8db $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 43
    15  Foundation                          0x0000000109f9b046 _writeJSONObject + 466
    16  Foundation                          0x0000000109f9ba98 ___writeJSONObject_block_invoke + 176
    17  libswiftCore.dylib                  0x000000010bc2f481 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 897
    18  libswiftCore.dylib                  0x000000010ba4f8db $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 43
    19  Foundation                          0x0000000109f9b046 _writeJSONObject + 466
    20  Foundation                          0x0000000109f9ba98 ___writeJSONObject_block_invoke + 176
    21  libswiftCore.dylib                  0x000000010bc2f481 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 897
    22  libswiftCore.dylib                  0x000000010ba4f8db $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 43
    23  Foundation                          0x0000000109f9b046 _writeJSONObject + 466
    24  Foundation                          0x0000000109f97826 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
    25  Foundation                          0x0000000109f9a3b7 +[NSJSONSerialization dataWithJSONObject:options:error:] + 337
    26  Gigya                               0x000000010a8165db $sSD5GigyaE6asJsonSSvgSS_ypTg5 + 459
    27  Gigya                               0x000000010a87ac4e $s5Gigya20PluginViewControllerC11sendRequest33_AECB03F2DE2968001A01CE9A6BBBD70ALL10callbackId9apiMethod6paramsySS_SSSDyS2SGtFyAA0A9ApiResultOySDySSAA10AnyCodableVGGcfU_ + 926
    28  Gigya                               0x000000010a87d49d $s5Gigya20PluginViewControllerC11sendRequest33_AECB03F2DE2968001A01CE9A6BBBD70ALL10callbackId9apiMethod6paramsySS_SSSDyS2SGtFyAA0A9ApiResultOySDySSAA10AnyCodableVGGcfU_TATm + 29
    29  Gigya                               0x000000010a87d3e0 $s5Gigya20PluginViewControllerC11sendRequest33_AECB03F2DE2968001A01CE9A6BBBD70ALL10callbackId9apiMethod6paramsySS_SSSDyS2SGtFyAA0A9ApiResultOySDySSAA10AnyCodableVGGcfU_TA + 16
    30  Gigya                               0x000000010a844bd6 $s5Gigya0A9ApiResultOySDySSAA10AnyCodableVGGIegg_AGIegn_TRTA + 38
    31  Gigya                               0x000000010a845959 $s5Gigya0A9ApiResultOySDySSAA10AnyCodableVGGIegg_AGIegn_TRTA.69 + 9
    32  Gigya                               0x000000010a83bd18 $s5Gigya10ApiServiceC14validateResult33_D119E9E6D70D9DCFB59B48B23E442E39LL12responseType4data10completionyxm_So6NSDataCSgyAA0abE0OyxGctSeRzSERzlF + 1944
    33  Gigya                               0x000000010a83b1cf $s5Gigya10ApiServiceC4send5model12responseType10completionyAA0B12RequestModelV_xmyAA0aB6ResultOyxGctSeRzSERzlFySo6NSDataCSg_s5Error_pSgtcfU_ + 1151
    34  Gigya                               0x000000010a83b579 $s5Gigya10ApiServiceC4send5model12responseType10completionyAA0B12RequestModelV_xmyAA0aB6ResultOyxGctSeRzSERzlFySo6NSDataCSg_s5Error_pSgtcfU_TA + 41
    35  Gigya                               0x000000010a8782e4 $s5Gigya14NetworkAdapterC4send5model10completionyAA15ApiRequestModelV_ySo6NSDataCSg_s5Error_pSgtctFySo10GSResponseCSg_AMtcfU_ + 324
    36  Gigya                               0x000000010a879251 $s5Gigya14NetworkAdapterC4send5model10completionyAA15ApiRequestModelV_ySo6NSDataCSg_s5Error_pSgtctFySo10GSResponseCSg_AMtcfU_TA + 17
    37  Gigya                               0x000000010a878170 $sSo10GSResponseCSgs5Error_pSgIeggg_ACSo7NSErrorCSgIeyByy_TR + 64
    38  GigyaInfra                          0x000000010aa270b1 -[GSRequest finishWithResponse:error:] + 293
    39  GigyaInfra                          0x000000010aa268dc __33-[GSRequest sendValidatedRequest]_block_invoke_3 + 504
    40  GigyaInfra                          0x000000010aa226e7 +[GSResponse responseForMethod:data:completionHandler:] + 614
    41  GigyaInfra                          0x000000010aa265eb __33-[GSRequest sendValidatedRequest]_block_invoke_2 + 610
    42  CFNetwork                           0x000000010cbd1178 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
    43  CFNetwork                           0x000000010cbe7c56 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 172
    44  Foundation                          0x0000000109eb6412 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
    45  Foundation                          0x0000000109eb631a -[NSBlockOperation main] + 68
    46  Foundation                          0x0000000109eb31f4 -[__NSOperationInternal _start:] + 688
    47  Foundation                          0x0000000109eb8f5b __NSOQSchedule_f + 227
    48  libdispatch.dylib                   0x000000010c5cf725 _dispatch_block_async_invoke2 + 83
    49  libdispatch.dylib                   0x000000010c5c1db5 _dispatch_client_callout + 8
    50  libdispatch.dylib                   0x000000010c5cf080 _dispatch_main_queue_callback_4CF + 1540
    51  CoreFoundation                      0x000000010b4ff8a9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    52  CoreFoundation                      0x000000010b4f9f56 __CFRunLoopRun + 2310
    53  CoreFoundation                      0x000000010b4f9302 CFRunLoopRunSpecific + 626
    54  GraphicsServices                    0x000000010fd342fe GSEventRunModal + 65
    55  UIKitCore                           0x0000000116dfcba2 UIApplicationMain + 140
    56  GigyaTester                         0x00000001080f208b main + 75
    57  libdyld.dylib                       0x000000010c636541 start + 1
    58  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我不明白 GigyaDemoApp 中挂起注册的实现。这是他们的代码:

@IBAction func loginWithProviders(_ sender: Any) {
    gigya.socialLoginWith(providers: [.facebook, .google, .line], viewController: self, params: [:]) { [weak self] (result) in
        switch result {
        case .success(let data):
            print(data)
            self?.resultTextView?.text = data.toJson()
        case .failure(let error):
            print(error)

            guard let interruption = error.interruption else { return }
            // Evaluage interruption.
            switch interruption {
            case .pendingRegistration(let resolver):
                resolver.setAccount(params: ["data": ["specialCode": "20"]])
            case .pendingVerification(let regToken):
                print("regToken: \(regToken)")
            case .conflitingAccount(let resolver):
                resolver.linkToSite(loginId: resolver.conflictingAccount?.loginID ?? "", password: "123123")
            default:
                break
            }

        }
    }

}

我应该如何处理挂起的注册中断?

你好像忘了关闭方括号。

试试这个:

gigya.login(with: .facebook, viewController: self, completion: { (result) in

switch result {
case .success(let data):
    print(data)
case .failure(let error):
    print(error)

    guard let interruption = error.interruption else {
        gigya.logout { (_) in
        }
        return }
    // Evaluate interruption.
    switch interruption {
    case .pendingRegistration(let resolver):
        gigya.showScreenSet(with: "Default-RegistrationLogin" ,
                            viewController: self,
                            params:[ "startScreen": "gigya-complete-registration-screen"],
                            completion: { (res) in


        })
        break
    default:
        break
    }

}
})

另外此时无法在pendingRegistration中断中打开screenSet,需要打开自定义ViewController并使用resolver.setAccount更新需要的参数。