質問編集履歴
3
追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
AWScognitoのサインインに成功した場合に画面遷移したい
|
1
|
+
追記AWScognitoのサインインに成功した場合に画面遷移したい
|
test
CHANGED
@@ -66,185 +66,7 @@
|
|
66
66
|
|
67
67
|
```swift
|
68
68
|
|
69
|
-
import UIKit
|
70
|
-
|
71
|
-
import AWSCognitoAuth
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
class ViewController: UITableViewController, AWSCognitoAuthDelegate {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@IBOutlet weak var signInButton: UIBarButtonItem!
|
82
|
-
|
83
|
-
@IBOutlet weak var signOutButton: UIBarButtonItem!
|
84
|
-
|
85
|
-
var auth: AWSCognitoAuth = AWSCognitoAuth.default()
|
86
|
-
|
87
|
-
var session: AWSCognitoAuthUserSession?
|
88
|
-
|
89
|
-
var firstLoad: Bool = true
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
override func viewDidLoad() {
|
94
|
-
|
95
|
-
super.viewDidLoad()
|
96
|
-
|
97
|
-
self.auth.delegate = self;
|
98
|
-
|
99
|
-
if(self.auth.authConfiguration.appClientId.contains("SETME")){
|
100
|
-
|
101
|
-
self.alertWithTitle("Error", message: "Info.plist missing necessary config under AWS->CognitoUserPool->Default")
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
override func viewWillAppear(_ animated: Bool) {
|
112
|
-
|
113
|
-
super.viewWillAppear(animated)
|
114
|
-
|
115
|
-
if(self.firstLoad){
|
116
|
-
|
117
|
-
self.signInTapped(signInButton as Any)
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
self.firstLoad = false
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
func getViewController() -> UIViewController {
|
128
|
-
|
129
|
-
return self;
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
136
|
-
|
137
|
-
let token = getBestToken()
|
138
|
-
|
139
|
-
if((token) != nil){
|
140
|
-
|
141
|
-
return token!.claims.count
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
return 0
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
156
|
-
|
157
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
let token = getBestToken()
|
162
|
-
|
163
|
-
let key = Array(token!.claims.keys)[indexPath.row]
|
164
|
-
|
165
|
-
cell.textLabel?.text = key as? String
|
166
|
-
|
167
|
-
cell.detailTextLabel?.text = (token!.claims[key] as AnyObject).description
|
168
|
-
|
169
|
-
return cell
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
func getBestToken() -> AWSCognitoAuthUserSessionToken? {
|
182
|
-
|
183
|
-
if(self.session != nil){
|
184
|
-
|
185
|
-
if((self.session?.idToken) != nil){
|
186
|
-
|
187
|
-
return self.session?.idToken!
|
188
|
-
|
189
|
-
}else if((self.session?.accessToken) != nil){
|
190
|
-
|
191
|
-
return self.session?.accessToken!
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
return nil;
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
func refresh () {
|
204
|
-
|
205
|
-
DispatchQueue.main.async {
|
206
|
-
|
207
|
-
self.signInButton.isEnabled = self.session == nil
|
208
|
-
|
209
|
-
self.signOutButton.isEnabled = self.session != nil
|
210
|
-
|
211
|
-
self.tableView.reloadData()
|
212
|
-
|
213
|
-
self.title = self.session?.username;
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
func alertWithTitle(_ title:String, message:String?) -> Void {
|
222
|
-
|
223
|
-
DispatchQueue.main.async {
|
224
|
-
|
225
|
-
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
|
226
|
-
|
227
|
-
let action = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default) { (UIAlertAction) in
|
228
|
-
|
229
|
-
alert.dismiss(animated: false, completion: nil)
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
alert.addAction(action)
|
234
|
-
|
235
|
-
self.present(alert, animated: true, completion: nil)
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
69
|
+
@IBAction func signInTapped(_ sender: Any) {
|
248
70
|
|
249
71
|
self.auth.getSession { (session:AWSCognitoAuthUserSession?, error:Error?) in
|
250
72
|
|
@@ -268,7 +90,7 @@
|
|
268
90
|
|
269
91
|
|
270
92
|
|
271
|
-
|
93
|
+
@IBAction func signOutTapped(_ sender: Any) {
|
272
94
|
|
273
95
|
self.auth.signOut { (error:Error?) in
|
274
96
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
ビルドタイム、ランタイムには問題ありません。
|
42
42
|
|
43
43
|
画面遷移がされるようにコードの書き換えを行っていますが、うまくできません。
|
44
44
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
|
42
42
|
|
43
43
|
画面遷移がされるようにコードの書き換えを行っていますが、うまくできません。
|
44
44
|
|