Ios 服务配置为“nil”。在使用此方法之前,您需要配置'Info.plist'或设置'defaultServiceConfiguration'

Ios 服务配置为“nil”。在使用此方法之前,您需要配置'Info.plist'或设置'defaultServiceConfiguration',ios,aws-amplify,aws-appsync,aws-appsync-ios,Ios,Aws Amplify,Aws Appsync,Aws Appsync Ios,我正在尝试将现有AppSync API连接到我的iOS应用程序。 要执行此操作,我按照本页上的说明进行操作,但没有执行: amplify add api amplify push 我添加了我现有的AppSync API: amplify add codegen --apiId XXXXXXXXXXXXXXX amplify codegen 运行这些命令后,我将awsconfiguration.json和API.swift添加到我的项目中 执行设置后,我在AppDelegate文件中初始化了

我正在尝试将现有AppSync API连接到我的iOS应用程序。
要执行此操作,我按照本页上的说明进行操作,但没有执行:

amplify add api
amplify push
我添加了我现有的AppSync API:

amplify add codegen --apiId XXXXXXXXXXXXXXX
amplify codegen
运行这些命令后,我将
awsconfiguration.json
API.swift
添加到我的项目中

执行设置后,我在AppDelegate文件中初始化了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) 

显然,因为我使用的是旧版本的AWS SDK for iOS,所以无法同时使用
awscoConfiguration.json
文件和
Info.plist
文件中的
AWS
部分

为了解决这个问题,我从
构建阶段
->
复制捆绑资源
中删除了
awscoConfiguration.json
文件,并将该文件中的AppSync API详细信息添加到
Info.plist
文件中:

<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>
AWS
破解补丁
违约
阿皮乌尔
https://XXXXXXXXXXXXX.appsync-api.xx-xxxx-x.amazonaws.com/graphql
区域
xx-xxxx-x
AuthMode
API_密钥
阿皮基
XXXXXXXXXXXX
客户端数据库前缀
XXXXXXXX\u API\u密钥
...

AWSAPSyncServiceConfig()将使用默认的AWSInfo,它加载
AWSCOConfiguration.json
,您是否已在项目设置中确认,
构建阶段
->
复制捆绑包资源
完全具有该文件(名称也必须完全相同)@Bill Yes,在
构建阶段
->
复制捆绑资源
我有文件
awsconfiguration.json