AWS Cognito iOS(Swift)SDK在应用启动时缓存数据和崩溃

时间:2017-07-19 00:09:48

标签: ios aws-cognito

我有一个使用Amazon Cognito的iOS应用程序(在Swift中)。它工作正常,我可以使用池登录并注销。 但是在我的一个客户端设备上,它已经以某种方式缓存了凭据并且没有注销,每次打开应用程序时,它都会崩溃。 我已尝试多次但无法重现此问题。我已使用以下所有语句来清除缓存:

FTUser.currentUser()?.clear()
FTUserIdentity.currentIdentity()?.clear()
pool?.currentUser()?.globalSignOut()
pool?.clearAll()

要登录,我使用以下代码:

cognitoUser?.getDetails().continueWith(block: { (task) -> Any? in
})

func startPasswordAuthentication() -> AWSCognitoIdentityPasswordAuthentication {

    if (self.navigationController == nil) {
        self.navigationController = self.storyboard?.instantiateViewController(withIdentifier: "LOGIN_NAVIGATOR") as? UINavigationController
    }

    if (self.loginVC == nil) {
        self.loginVC = self.navigationController?.viewControllers[0] as? FTLoginVC
    }

    self.navigationController?.popToRootViewController(animated: true)
    if (!self.navigationController!.isViewLoaded || self.navigationController!.view.window == nil) {
        self.window?.rootViewController?.present(self.navigationController!, animated: true, completion: nil)
    }
    return self.loginVC!

}

我已经要求客户删除该应用并重新安装它但它仍然崩溃。这使我认为凭据已缓存在某处,即使删除并重新安装该应用,也无法删除凭据。亚马逊是否使用钥匙串存储密码,令牌等?

Incident Identifier: 180BF2FF-FBC6-4A9F-8766-C59ED8A46AC2
CrashReporter Key:   541741f4d4bf5b34b96b634d5625d003f1239d22
Hardware Model:      iPhone7,2
Process:             WSHC [812]
Path:                /private/var/containers/Bundle/Application/8E8E8373-A10E-4ED1-83A3-510ACE4269AE/WSHC.app/WSHC
Identifier:          com.fittraction.fitTraction
Version:             13 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.fittraction.fitTraction [537]


Date/Time:           2017-06-03 08:11:20.4738 -0700
Launch Time:         2017-06-03 08:11:16.3798 -0700
OS Version:          iPhone OS 10.3.1 (14E304)
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  8

Application Specific Information:
abort() called

Filtered syslog:
None found

Last Exception Backtrace:
(0x18a932fd8 0x189394538 0x18a932eac 0x18b3ca77c 0x1909873f8 0x1909870d8 0x1909b5e88 0x1909b9188 0x1909dd474 0x1909dcbb4 0x190b0e5d4 0x191496834 0x190f697f4 0x1910b796c 0x1910b7ae4 0x1910b76ac 0x190d47308 0x1910b796c 0x1910b7ae4 0x1910b76ac 0x190dc707c 0x100174880 0x100174920 0x190f697f4 0x1910b796c 0x1910b76ac 0x190f69498 0x190f69c38 0x1910b796c 0x1910b7ae4 0x1910b76ac 0x190f687d8 0x191222ea4 0x100110998 0x10011164c 0x1005e0a18 0x1005dc1e8 0x1007ac1e0 0x100752ac8 0x100753504 0x1007ac7a4 0x1007abc28 0x1007ab6b8 0x1007ad9d4 0x1007de8ac 0x1007accf4 0x1007ac1e0 0x100752ac8 0x100753504 0x1007ac0c8 0x1007acbfc 0x1007ace1c 0x1007dcc74 0x18b10a984 0x18b401804 0x18b346760 0x18b336b18 0x18b403ba0 0x1897ea9a0 0x1897f8ad4 0x1897ee2cc 0x1897faa50 0x1897fa7d0 0x1899f31d0 0x1899f2d7c)

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x000000018990f224 0x18990e000 + 4644
1   libsystem_kernel.dylib          0x000000018990f09c 0x18990e000 + 4252
2   CoreFoundation                  0x000000018a8e0e88 0x18a806000 + 896648
3   CoreFoundation                  0x000000018a8deadc 0x18a806000 + 887516
4   CoreFoundation                  0x000000018a80ed94 0x18a806000 + 36244
5   GraphicsServices                0x000000018c278074 0x18c26c000 + 49268
6   UIKit                           0x0000000190ac7130 0x190a52000 + 479536
7   WSHC                            0x0000000100117740 0x1000ac000 + 440128
8   libdyld.dylib                   0x000000018981d59c 0x189819000 + 17820

Thread 1:
0   libsystem_kernel.dylib          0x000000018992da88 0x18990e000 + 129672
1   libsystem_pthread.dylib         0x00000001899f3274 0x1899f2000 + 4724
2   libsystem_pthread.dylib         0x00000001899f2d7c 0x1899f2000 + 3452

Thread 2:
0   libsystem_pthread.dylib         0x00000001899f2d78 0x1899f2000 + 3448

Thread 3:
0   libsystem_pthread.dylib         0x00000001899f2d78 0x1899f2000 + 3448

Thread 4:
0   libsystem_pthread.dylib         0x00000001899f2d78 0x1899f2000 + 3448

Thread 5:
0   libsystem_kernel.dylib          0x000000018992da88 0x18990e000 + 129672
1   libsystem_pthread.dylib         0x00000001899f3274 0x1899f2000 + 4724
2   libsystem_pthread.dylib         0x00000001899f2d7c 0x1899f2000 + 3452

Thread 6 name:  com.apple.uikit.eventfetch-thread
Thread 6:
0   libsystem_kernel.dylib          0x000000018990f224 0x18990e000 + 4644
1   libsystem_kernel.dylib          0x000000018990f09c 0x18990e000 + 4252
2   CoreFoundation                  0x000000018a8e0e88 0x18a806000 + 896648
3   CoreFoundation                  0x000000018a8deadc 0x18a806000 + 887516
4   CoreFoundation                  0x000000018a80ed94 0x18a806000 + 36244
5   Foundation                      0x000000018b328d64 0x18b31c000 + 52580
6   Foundation                      0x000000018b349b34 0x18b31c000 + 187188
7   UIKit                           0x00000001914515f8 0x190a52000 + 10483192
8   Foundation                      0x000000018b4262c8 0x18b31c000 + 1090248
9   libsystem_pthread.dylib         0x00000001899f575c 0x1899f2000 + 14172
10  libsystem_pthread.dylib         0x00000001899f566c 0x1899f2000 + 13932
11  libsystem_pthread.dylib         0x00000001899f2d84 0x1899f2000 + 3460

Thread 7 name:  com.twitter.crashlytics.ios.MachExceptionServer
Thread 7:
0   libsystem_kernel.dylib          0x000000018990f224 0x18990e000 + 4644
1   libsystem_kernel.dylib          0x000000018990f09c 0x18990e000 + 4252
2   WSHC                            0x000000010027f5c4 0x1000ac000 + 1914308
3   libsystem_pthread.dylib         0x00000001899f575c 0x1899f2000 + 14172
4   libsystem_pthread.dylib         0x00000001899f566c 0x1899f2000 + 13932
5   libsystem_pthread.dylib         0x00000001899f2d84 0x1899f2000 + 3460

Thread 8 name:  Dispatch queue: NSOperationQueue 0x17403c6e0 :: NSOperation 0x17405e7e0 (QOS: DEFAULT)
Thread 8 Crashed:
0   libsystem_kernel.dylib          0x000000018992d014 0x18990e000 + 126996
1   libsystem_pthread.dylib         0x00000001899f7334 0x1899f2000 + 21300
2   libsystem_c.dylib               0x00000001898a1a60 0x189840000 + 399968
3   libsystem_c.dylib               0x00000001898a19d0 0x189840000 + 399824
4   libc++abi.dylib                 0x000000018936d1b0 0x18936c000 + 4528
5   libc++abi.dylib                 0x0000000189386c04 0x18936c000 + 109572
6   libobjc.A.dylib                 0x0000000189394820 0x18938c000 + 34848
7   WSHC                            0x00000001002925c0 0x1000ac000 + 1992128
8   libc++abi.dylib                 0x00000001893835d4 0x18936c000 + 95700
9   libc++abi.dylib                 0x0000000189383640 0x18936c000 + 95808
10  libdispatch.dylib               0x00000001897ea9b4 0x1897e9000 + 6580
11  libdispatch.dylib               0x00000001897f8ad4 0x1897e9000 + 64212
12  libdispatch.dylib               0x00000001897ee2cc 0x1897e9000 + 21196
13  libdispatch.dylib               0x00000001897faa50 0x1897e9000 + 72272
14  libdispatch.dylib               0x00000001897fa7d0 0x1897e9000 + 71632
15  libsystem_pthread.dylib         0x00000001899f31d0 0x1899f2000 + 4560
16  libsystem_pthread.dylib         0x00000001899f2d7c 0x1899f2000 + 3452

Thread 9:
0   libsystem_pthread.dylib         0x00000001899f2d78 0x1899f2000 + 3448

Thread 10 name:  com.apple.NSURLConnectionLoader
Thread 10:
0   libsystem_kernel.dylib          0x000000018990f224 0x18990e000 + 4644
1   libsystem_kernel.dylib          0x000000018990f09c 0x18990e000 + 4252
2   CoreFoundation                  0x000000018a8e0e88 0x18a806000 + 896648
3   CoreFoundation                  0x000000018a8deadc 0x18a806000 + 887516
4   CoreFoundation                  0x000000018a80ed94 0x18a806000 + 36244
5   CFNetwork                       0x000000018b01aca4 0x18af39000 + 924836
6   Foundation                      0x000000018b4262c8 0x18b31c000 + 1090248
7   libsystem_pthread.dylib         0x00000001899f575c 0x1899f2000 + 14172
8   libsystem_pthread.dylib         0x00000001899f566c 0x1899f2000 + 13932
9   libsystem_pthread.dylib         0x00000001899f2d84 0x1899f2000 + 3460

2 个答案:

答案 0 :(得分:0)

您可以将一个值写入UserDefaults以指示某个应用程序之前已启动。 如果应用程序是第一次启动,请注销以重置凭据。

let defaults:UserDefaults = UserDefaults.standard
if let hasBeenOpenedBefore:Bool = defaults.bool(forKey: "hasBeenOpenedBefore") {
  if hasBeenOpenedBefore == false {
    defaults.set(true, forKey: "hasBeenOpenedBefore")
    logout()
  }
}

答案 1 :(得分:0)

需要检查是否显示了活动视图控制器,如果不是,则在这种情况下应显示:

func startPasswordAuthentication() -> AWSCognitoIdentityPasswordAuthentication {

        if (self.navigationController == nil) {
            self.navigationController = self.storyboard?.instantiateViewController(withIdentifier: "LOGIN_NAVIGATOR") as? UINavigationController
        }

        if (self.loginVC == nil) {
            self.loginVC = self.navigationController?.viewControllers[0] as? FTLoginVC
        }
        DispatchQueue.main.async {
            self.navigationController?.popToRootViewController(animated: true)
            if (!self.navigationController!.isViewLoaded || self.navigationController!.view.window == nil) && !(self.navigationController?.isBeingPresented ?? true) {
                self.window?.rootViewController?.present(self.navigationController!, animated: true, completion: nil)
            }
        }
        return self.loginVC!

    }

您可以使用上面的代码块,让我知道它是否有效!