質問編集履歴
3
追記
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
AWScognitoのサインインに成功した場合に画面遷移したい
|
1
|
+
追記AWScognitoのサインインに成功した場合に画面遷移したい
|
body
CHANGED
@@ -32,96 +32,7 @@
|
|
32
32
|
### 該当のソースコード
|
33
33
|
|
34
34
|
```swift
|
35
|
-
import UIKit
|
36
|
-
import AWSCognitoAuth
|
37
|
-
|
38
|
-
class ViewController: UITableViewController, AWSCognitoAuthDelegate {
|
39
|
-
|
40
|
-
|
41
|
-
@IBOutlet weak var signInButton: UIBarButtonItem!
|
42
|
-
@IBOutlet weak var signOutButton: UIBarButtonItem!
|
43
|
-
var auth: AWSCognitoAuth = AWSCognitoAuth.default()
|
44
|
-
var session: AWSCognitoAuthUserSession?
|
45
|
-
var firstLoad: Bool = true
|
46
|
-
|
47
|
-
override func viewDidLoad() {
|
48
|
-
super.viewDidLoad()
|
49
|
-
self.auth.delegate = self;
|
50
|
-
if(self.auth.authConfiguration.appClientId.contains("SETME")){
|
51
|
-
self.alertWithTitle("Error", message: "Info.plist missing necessary config under AWS->CognitoUserPool->Default")
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
override func viewWillAppear(_ animated: Bool) {
|
57
|
-
super.viewWillAppear(animated)
|
58
|
-
if(self.firstLoad){
|
59
|
-
self.signInTapped(signInButton as Any)
|
60
|
-
}
|
61
|
-
self.firstLoad = false
|
62
|
-
}
|
63
|
-
|
64
|
-
func getViewController() -> UIViewController {
|
65
|
-
return self;
|
66
|
-
}
|
67
|
-
|
68
|
-
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
69
|
-
let token = getBestToken()
|
70
|
-
if((token) != nil){
|
71
|
-
return token!.claims.count
|
72
|
-
}
|
73
|
-
return 0
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
79
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
80
|
-
|
81
|
-
let token = getBestToken()
|
82
|
-
let key = Array(token!.claims.keys)[indexPath.row]
|
83
|
-
cell.textLabel?.text = key as? String
|
84
|
-
cell.detailTextLabel?.text = (token!.claims[key] as AnyObject).description
|
85
|
-
return cell
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
func getBestToken() -> AWSCognitoAuthUserSessionToken? {
|
92
|
-
if(self.session != nil){
|
93
|
-
if((self.session?.idToken) != nil){
|
94
|
-
return self.session?.idToken!
|
95
|
-
}else if((self.session?.accessToken) != nil){
|
96
|
-
return self.session?.accessToken!
|
97
|
-
}
|
98
|
-
}
|
99
|
-
return nil;
|
100
|
-
}
|
101
|
-
|
102
|
-
func refresh () {
|
103
|
-
DispatchQueue.main.async {
|
104
|
-
self.signInButton.isEnabled = self.session == nil
|
105
|
-
self.signOutButton.isEnabled = self.session != nil
|
106
|
-
self.tableView.reloadData()
|
107
|
-
self.title = self.session?.username;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
func alertWithTitle(_ title:String, message:String?) -> Void {
|
112
|
-
DispatchQueue.main.async {
|
113
|
-
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
|
114
|
-
let action = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default) { (UIAlertAction) in
|
115
|
-
alert.dismiss(animated: false, completion: nil)
|
116
|
-
}
|
117
|
-
alert.addAction(action)
|
118
|
-
self.present(alert, animated: true, completion: nil)
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
35
|
+
@IBAction func signInTapped(_ sender: Any) {
|
125
36
|
self.auth.getSession { (session:AWSCognitoAuthUserSession?, error:Error?) in
|
126
37
|
if(error != nil) {
|
127
38
|
self.session = nil
|
@@ -133,7 +44,7 @@
|
|
133
44
|
}
|
134
45
|
}
|
135
46
|
|
136
|
-
|
47
|
+
@IBAction func signOutTapped(_ sender: Any) {
|
137
48
|
self.auth.signOut { (error:Error?) in
|
138
49
|
if(error != nil){
|
139
50
|
self.alertWithTitle("Error", message: (error! as NSError).userInfo["error"] as? String)
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
### 発生している問題・エラーメッセージ
|
19
19
|
|
20
20
|
```
|
21
|
-
|
21
|
+
ビルドタイム、ランタイムには問題ありません。
|
22
22
|
画面遷移がされるようにコードの書き換えを行っていますが、うまくできません。
|
23
23
|
|
24
24
|
Thread 1: signal SIGABRT
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
### 発生している問題・エラーメッセージ
|
19
19
|
|
20
20
|
```
|
21
|
-
|
21
|
+
|
22
22
|
画面遷移がされるようにコードの書き換えを行っていますが、うまくできません。
|
23
23
|
|
24
24
|
Thread 1: signal SIGABRT
|