首页 > 解决方案 > NSMutableDictionary 无法转换为 ASAuthorizationAppleIDRequest

问题描述

我正在使用这个库在 React Native 中实现 Apple 登录: https ://github.com/invertase/react-native-apple-authentication 并且有一个用于 Apple 登录按钮的 onPress 事件的处理程序,如下所示:

import { appleAuth } from '@invertase/react-native-apple-authentication';

async function onAppleButtonPress() {
  // performs login request
  const appleAuthRequestResponse = await appleAuth.performRequest({
    requestedOperation: appleAuth.Operation.LOGIN,
    requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
  });

  // get current authentication state for user
  // /!\ This method must be tested on a real device. On the iOS simulator it always throws an error.
  const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);

  // use credentialState response to ensure the user is authenticated
  if (credentialState === appleAuth.State.AUTHORIZED) {
    // user is authenticated
  }
}

但是,当我像这样将其转换为 clojurescript 时:

(reg-fx
 :apple-signin-fx
 (fn [navigation]
   (go (let [appleAuthRequestResponse
             (<p! (.performRequest appleAuth
                                   (clj->js
                                    {:requestedOperation (.. appleAuth -Operation -LOGIN)
                                     :requestedScopes [(.. appleAuth -Scope -Email)
                                                       (.. appleAuth -Scope -FULL_NAME)]})))]))))

我收到以下错误:

JSON value '{
    nonceEnabled = 1;
    requestedOperation = 1;
    requestedScopes =     (
        "<null>",
        1
    );
}' of type NSMutableDictionary cannot be converted to ASAuthorizationAppleIDRequest *

+[RCTConvert(ASAuthorizationAppleIDRequest) ASAuthorizationAppleIDRequest:]
    RCTConvert+ASAuthorizationAppleIDRequest.m:85
__41-[RCTModuleMethod processMethodSignature]_block_invoke_16
-[RCTModuleMethod invokeWithBridge:module:arguments:]
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start

如何解决这个问题?

标签: react-nativeclojurescript

解决方案


推荐阅读