前提・実現したいこと
AWSMobileHubを利用してUserSign-inの機能を追加したい
参考にしたページ
https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-user-sign-in.html
状況
シンタックスエラーではなく、一旦はビルドが通るのですが、すぐに落ちてしまいます。
↓エラーコード
Fatal error: Unexpectedly found nil while unwrapping an Optional value
該当のソースコード
↓ViewContollerのコード
swift
1import UIKit 2import AWSAuthCore 3import AWSAuthUI 4 5class ViewController: UIViewController { 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 11 if !AWSSignInManager.sharedInstance().isLoggedIn { 12 AWSAuthUIViewController 13 .presentViewController(with: self.navigationController!, 14 configuration: nil, 15 completionHandler: { (provider: AWSSignInProvider, error: Error?) in 16 if error != nil { 17 print("Error occurred: (String(describing: error))") 18 } else { 19 // Sign in successful. 20 } 21 }) 22 } 23 24 } 25 26 override func didReceiveMemoryWarning() { 27 super.didReceiveMemoryWarning() 28 // Dispose of any resources that can be recreated. 29 } 30 31 32}
↓AppDelegateのコード
swift
1import UIKit 2import AWSCore 3import AWSMobileClient 4import AWSPinpoint 5 6@UIApplicationMain 7class AppDelegate: UIResponder, UIApplicationDelegate { 8 9 var pinpoint: AWSPinpoint? 10 11 var window: UIWindow? 12 13 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 14 // Override point for customization after application launch. 15 16 // Initialize Pinpoint 17 pinpoint = AWSPinpoint(configuration: 18 AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions)) 19 20 return AWSMobileClient.sharedInstance().interceptApplication( 21 application, 22 didFinishLaunchingWithOptions: launchOptions) 23 } 24 25 // Add a AWSMobileClient call in application:open url 26 func application(_ application: UIApplication, open url: URL, 27 sourceApplication: String?, annotation: Any) -> Bool { 28 29 return AWSMobileClient.sharedInstance().interceptApplication( 30 application, open: url, 31 sourceApplication: sourceApplication, 32 annotation: annotation) 33 34 } 35//・・・ 36}
試したこと
-予期せぬnillが入っていたため起きたエラーだというのは分かったのですが、アンラップの方法を?や??に変えましたが、エラーが出ました。
-AWS公式のコードをそのままコピペしたにも関わらずエラーが出たため、バージョンの違いによるものか、自分のxcodeの設定がおかしいのかと考えていますが、対処の方法がわかりません・・・
補足情報(FW/ツールのバージョンなど)
xcode Version 9.3
ios 11.3
cocoapods 1.5.0
↓導入したPods
AWSAuthCore (2.6.16)
AWSAuthUI (2.6.16)
AWSCognitoIdentityProvider (2.6.16)
AWSCognitoIdentityProviderASF (1.0.1)
AWSCore (2.6.16)
AWSMobileClient (2.6.16)
AWSPinpoint (2.6.16)
AWSUserPoolsSignIn (2.6.16)
回答1件
あなたの回答
tips
プレビュー