当前位置: 首页 > 知识库问答 >
问题:

服务配置为'nil'。在使用此方法之前,您需要配置nfo.plist或设置默认服务配置

袁鹤轩
2023-03-14

我试图将现有的AppSync API连接到我的iOS应用程序。
为了执行此操作,我遵循了此页面的说明:https://docs.amplify.aws/cli/graphql-transformer/codegen#ios-usage,但没有执行:

amplify add api
amplify push

我添加了我现有的AppSync API:

amplify add codegen --apiId XXXXXXXXXXXXXXX
amplify codegen

运行这些命令后,我将awsconfiguration.jsonAPI. swyft添加到我的项目中。

执行安装后,我在App委托文件中初始化了AppSync客户端:

import AWSAppSync

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var appSyncClient: AWSAppSyncClient?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        do {
            // You can choose your database location if you wish, or use the default
            let cacheConfiguration = try AWSAppSyncCacheConfiguration()

            // AppSync configuration & client initialization
            let appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: AWSAppSyncServiceConfig(), cacheConfiguration: cacheConfiguration)
            appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig)
        } catch {
            print("Error initializing appsync client. \(error)")
        }
    }
}

值得一提的是,我在我的应用程序中使用了AWS SDK(对于使用对象映射器的DynamoDB)(之前的SDK,尚未放大)

问题是,当我运行应用程序时,它会立即崩溃
这是崩溃时附带的日志消息:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   AWSDynamoDB                         0x000000010be77baa __54+[AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper]_block_invoke + 474
    3   libdispatch.dylib                   0x000000010cb04d48 _dispatch_client_callout + 8
    4   libdispatch.dylib                   0x000000010cb06297 _dispatch_once_callout + 66
    5   AWSDynamoDB                         0x000000010be779a4 +[AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper] + 84
    6   App                                 0x000000010a7d0f9c $s22App10GlobalVarsCACycfc + 140
    7   App                                 0x000000010a7ca97c $s22App10GlobalVarsCACycfC + 60
    8   App                                 0x000000010a7fd7e1 $s22App21LoadingViewControllerC5coderACSgSo7NSCoderC_tcfc + 113
    9   App                                 0x000000010a7fd943 $s22App21LoadingViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 51
    10  UIKitCore                           0x00007fff47cf7268 -[UIClassSwapper initWithCoder:] + 2427
    11  UIFoundation                        0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744
    12  UIFoundation                        0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423
    13  UIFoundation                        0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251
    14  UIKitCore                           0x00007fff47cf6531 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsAndTrackChildViewControllerIndexWithParent:forKey:] + 298
    15  UIKitCore                           0x00007fff47a0e65d -[UIViewController initWithCoder:] + 1419
    16  UIKitCore                           0x00007fff4795cc16 -[UINavigationController initWithCoder:] + 65
    17  UIKitCore                           0x00007fff47cf7268 -[UIClassSwapper initWithCoder:] + 2427
    18  UIFoundation                        0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744
    19  UIFoundation                        0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251
    20  UIKitCore                           0x00007fff47cfb56f -[UIRuntimeConnection initWithCoder:] + 125
    21  UIFoundation                        0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744
    22  UIFoundation                        0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423
    23  UIFoundation                        0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251
    24  UIKitCore                           0x00007fff47cf6336 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsWithSourceSegueTemplate:creator:sender:forKey:] + 450
    25  UIKitCore                           0x00007fff47cf90a5 -[UINib instantiateWithOwner:options:] + 1145
    26  UIKitCore                           0x00007fff481f8f24 -[UIStoryboard __reallyInstantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 279
    27  UIKitCore                           0x00007fff481f8dcf -[UIStoryboard _instantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 97
    28  UIKitCore                           0x00007fff48091ebf -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 167
    29  UIKitCore                           0x00007fff48092473 -[UIApplication _loadMainInterfaceFile] + 274
    30  UIKitCore                           0x00007fff48090dff -[UIApplication _runWithMainScene:transitionContext:completion:] + 964
    31  UIKitCore                           0x00007fff477c576d -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122
    32  UIKitCore                           0x00007fff47cb44c1 _UIScenePerformActionsWithLifecycleActionMask + 83
    33  UIKitCore                           0x00007fff477c627f __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198
    34  UIKitCore                           0x00007fff477c5c8e -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296
    35  UIKitCore                           0x00007fff477c60ac -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 818
    36  UIKitCore                           0x00007fff477c5941 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 345
    37  UIKitCore                           0x00007fff477c9f3f __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 178
    38  UIKitCore                           0x00007fff47bd8c83 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 865
    39  UIKitCore                           0x00007fff47cd2dff _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 240
    40  UIKitCore                           0x00007fff477c9c5a __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 153
    41  UIKitCore                           0x00007fff47cd2d02 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 84
    42  UIKitCore                           0x00007fff477c9ac8 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 381
    43  UIKitCore                           0x00007fff476206e7 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 657
    44  UIKitCore                           0x00007fff4761f26c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248
    45  UIKitCore                           0x00007fff47620411 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 210
    46  UIKitCore                           0x00007fff4808f599 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 535
    47  UIKitCore                           0x00007fff47bfa7f5 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    48  FrontBoardServices                  0x00007fff365d6165 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442
    49  FrontBoardServices                  0x00007fff365fc4d8 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
    50  FrontBoardServices                  0x00007fff365e0c45 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
    51  FrontBoardServices                  0x00007fff365fc169 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
    52  libdispatch.dylib                   0x000000010cb04d48 _dispatch_client_callout + 8
    53  libdispatch.dylib                   0x000000010cb07cb9 _dispatch_block_invoke_direct + 300
    54  FrontBoardServices                  0x00007fff3662237e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    55  FrontBoardServices                  0x00007fff3662206c -[FBSSerialQueue _queue_performNextIfPossible] + 441
    56  FrontBoardServices                  0x00007fff3662257b -[FBSSerialQueue _performNextFromRunLoopSource] + 22
    57  CoreFoundation                      0x00007fff23bd4471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    58  CoreFoundation                      0x00007fff23bd439c __CFRunLoopDoSource0 + 76
    59  CoreFoundation                      0x00007fff23bd3b74 __CFRunLoopDoSources0 + 180
    60  CoreFoundation                      0x00007fff23bce87f __CFRunLoopRun + 1263
    61  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    62  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
    63  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
    64  App                                 0x000000010a841728 main + 72
    65  libdyld.dylib                       0x00007fff5227ec25 start + 1
    66  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

共有1个答案

宰修能
2023-03-14

显然,因为我使用的是旧版本的AWS SDK for iOS,所以不能同时使用AWS配置。json文件和Info中的AWS部分。plist文件。

为了解决这个问题,我删除了aws配置。json来自构建阶段的文件-

<key>AWS</key>
<dict>
    <key>AppSync</key>
    <dict>
        <key>Default</key>
        <dict>
            <key>ApiUrl</key>
            <string>https://XXXXXXXXXXXXX.appsync-api.xx-xxxx-x.amazonaws.com/graphql</string>
            <key>Region</key>
            <string>xx-xxxx-x</string>
            <key>AuthMode</key>
            <string>API_KEY</string>
            <key>ApiKey</key>
            <string>XXXXXXXXXXXXX</string>
            <key>ClientDatabasePrefix</key>
            <string>XXXXXXXX_API_KEY
        </dict>
    </dict>
    ...
</dict>
 类似资料:
  • 介绍常用的服务配置。 云联壹云 平台支持基于climc命令修改常用服务配置。 说明 请确保First Node节点已正确初始化climc工具,配置步骤请参考CLIMC工具 通用配置命令如下 目前支持配置的服务有keystone、glance、region2、yunionapi、common等。 命令模式 在命令行下输入climc并带额定的参数获取相应的结果。 # 查看服务的配置信息 $ climc

  • 我们来看看如何配置服务器端的 SSH 访问。 本例中,我们将使用 authorized_keys 方法来对用户进行认证。 同时我们假设你使用的操作系统是标准的 Linux 发行版,比如 Ubuntu。 首先,创建一个操作系统用户 git,并为其建立一个 .ssh 目录。 $ sudo adduser git $ su git $ cd $ mkdir .ssh && chmod 700 .ssh

  • 【什么是squid】 Squid是比较知名的代理软件,它不仅可以跑在linux上还可以跑在windows以及Unix上,它的技术已经非常成熟。目前使用Squid的用户也是十分广泛的。Squid与Linux下其它的代理软件如Apache、Socks、TIS FWTK和delegate相比,下载安装简单,配置简单灵活,支持缓存和多种协议。 Squid的缓存功能相当好用,不仅可以减少带宽的占用,同样也大

  • 【什么是FTP】 也许你对FTP不陌生,但是你是否了解FTP到底是个什么玩意?FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”。用于Internet上的控制文件的双向传输。同时,它也是一个应用程序(Application)。用户可以通过它把自己的PC机与世界各地所有运行FTP协议的服务器相连,访问服务器上的大量程序和信息。FTP的主要作用,

  • 【什么是NFS】 NFS会经常用到,用于在网络上共享存储。这样讲,你对NFS可能不太了解,笔者不妨举一个例子来说明一下NFS是用来做什么的。假如有三台机器A、B、C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A、B、C。但是使用NFS只需要放到A上,然后A共享给B和C即可。访问的时候,B和C是通过网络的方式去访问A上的那个目录的。 【配置NFS】 NFS配置起来还是蛮简

  • 服务器配置 当你需要一台服务器的时候,首先需要向你的leader 提出申请,你的 leader 会利用公司的阿里云账户购买服务器实例,并且会把服务器的公网IP以及账号密码发送给你。 以下章节就叙述了当拿到一台全新的阿里云服务器实例时,我们需要怎样的工具以及我们需要经历哪些步骤对服务器进行配置。