質問編集履歴
2
写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -325,3 +325,7 @@
|
|
325
325
|
|
326
326
|
|
327
327
|
```
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
![Simulator](199cd982f760f0c4429c6793a745afb8.png)
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,3 +11,317 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
![こちらです](2986ecb01909374ebf67fcacaa2f0a5c.png)
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```ViewController
|
20
|
+
|
21
|
+
import UIKit
|
22
|
+
|
23
|
+
import FBSDKCoreKit
|
24
|
+
|
25
|
+
import FBSDKLoginKit
|
26
|
+
|
27
|
+
import FacebookCore
|
28
|
+
|
29
|
+
import FacebookLogin
|
30
|
+
|
31
|
+
import Firebase
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
class ViewController: UIViewController,LoginButtonDelegate {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
let fbLoginButton:FBLoginButton = FBLoginButton()
|
46
|
+
|
47
|
+
var displayName = String()
|
48
|
+
|
49
|
+
var pictureURL = String()
|
50
|
+
|
51
|
+
var pictureURLString = String()
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
override func viewDidLoad() {
|
58
|
+
|
59
|
+
super.viewDidLoad()
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
fbLoginButton.delegate = self
|
64
|
+
|
65
|
+
fbLoginButton.frame = CGRect(x: view.frame.size.width/2 - view.frame.size.width/4, y: view.frame.size.height/4 , width: view.frame.size.width/2, height: 30)
|
66
|
+
|
67
|
+
fbLoginButton.permissions = ["public_profile,email"]
|
68
|
+
|
69
|
+
view.addSubview(fbLoginButton)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
override func viewWillAppear(_ animated: Bool) {
|
82
|
+
|
83
|
+
super.viewWillAppear(animated)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
navigationController?.isNavigationBarHidden = true
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) {
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
if error == nil{
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
if result?.isCancelled == true{
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
return
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)
|
126
|
+
|
127
|
+
Auth.auth().signIn(with: credential) { (result, error) in
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if let error = error{
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
return
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
self.displayName = result!.user.displayName!
|
144
|
+
|
145
|
+
self.pictureURLString = result!.user.photoURL!.absoluteString
|
146
|
+
|
147
|
+
self.pictureURLString = self.pictureURLString + "?type=large"
|
148
|
+
|
149
|
+
UserDefaults.standard.set(1, forKey: "loginOK")
|
150
|
+
|
151
|
+
UserDefaults.standard.set(self.displayName, forKey: "displayName")
|
152
|
+
|
153
|
+
UserDefaults.standard.set(self.pictureURLString, forKey: "pictureURLString")
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
let nextVC = self.storyboard?.instantiateViewController(identifier: "next") as! NextViewController
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
self.navigationController?.pushViewController(nextVC, animated: true)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
func loginButtonWillLogin(_ loginButton: FBLoginButton) -> Bool {
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
return true
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
|
198
|
+
|
199
|
+
print("ログアウトしました!")
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
```NextViewController
|
222
|
+
|
223
|
+
import UIKit
|
224
|
+
|
225
|
+
import SDWebImage
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
class NextViewController: UIViewController {
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
@IBOutlet weak var profileImageView: UIImageView!
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
@IBOutlet weak var userNameLabel: UILabel!
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
override func viewDidLoad() {
|
244
|
+
|
245
|
+
super.viewDidLoad()
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if UserDefaults.standard.object(forKey: "pictureURLString") != nil || (UserDefaults.standard.object(forKey: "displayName") != nil){
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
let imageString = UserDefaults.standard.object(forKey: "pictureURLString") as! String
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
profileImageView.sd_setImage(with: URL(string: imageString), completed: nil)
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
profileImageView.layer.cornerRadius = 20.0
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
let displayName = UserDefaults.standard.object(forKey: "displayName") as! String
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
userNameLabel.text = displayName
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
// Do any additional setup after loading the view.
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
override func viewWillAppear(_ animated: Bool) {
|
290
|
+
|
291
|
+
super.viewWillAppear(animated)
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
navigationController?.isNavigationBarHidden = true
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
/*
|
304
|
+
|
305
|
+
// MARK: - Navigation
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
310
|
+
|
311
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
312
|
+
|
313
|
+
// Get the new view controller using segue.destination.
|
314
|
+
|
315
|
+
// Pass the selected object to the new view controller.
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
*/
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
```
|