服务配置为“无”。使用此方法前需要配置`Info.plist`或设置`defaultServiceConfiguration`
The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method
我正在尝试将现有的 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.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)")
}
}
}
值得一提的是,我在我的应用程序(以前的 SDK,还没有 Amplify)中使用 AWS SDK(对于使用对象映射器的 DynamoDB)
问题是,当我 运行 应用程序时,它会立即崩溃。
这是崩溃附带的日志消息:
*** 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)
显然,因为我在 iOS 使用旧版本的 AWS SDK,所以我无法同时使用 awsconfiguration.json
文件和 Info.plist
中的 AWS
部分] 文件。
为了解决它,我从 Build Phases
-> Copy Bundle Resources
中删除了 awsconfiguration.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>
我正在尝试将现有的 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.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)")
}
}
}
值得一提的是,我在我的应用程序(以前的 SDK,还没有 Amplify)中使用 AWS SDK(对于使用对象映射器的 DynamoDB)
问题是,当我 运行 应用程序时,它会立即崩溃。
这是崩溃附带的日志消息:
*** 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)
显然,因为我在 iOS 使用旧版本的 AWS SDK,所以我无法同时使用 awsconfiguration.json
文件和 Info.plist
中的 AWS
部分] 文件。
为了解决它,我从 Build Phases
-> Copy Bundle Resources
中删除了 awsconfiguration.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>