質問編集履歴
2
写真の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -161,4 +161,6 @@
|
|
161
161
|
|
162
162
|
}
|
163
163
|
|
164
|
-
```
|
164
|
+
```
|
165
|
+
|
166
|
+

|
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,161 @@
|
|
4
4
|
今回の質問なのですが、Facebookログインのアプリケーションを作成したのですが、ContinueWithFacebookというボタンがLabelが隠れてしまうのですが移動させる方法は何かあるのでしょうか。
|
5
5
|
よろしくお願い致します。
|
6
6
|
|
7
|
-

|
7
|
+

|
8
|
+
|
9
|
+
|
10
|
+
```ViewController
|
11
|
+
import UIKit
|
12
|
+
import FBSDKCoreKit
|
13
|
+
import FBSDKLoginKit
|
14
|
+
import FacebookCore
|
15
|
+
import FacebookLogin
|
16
|
+
import Firebase
|
17
|
+
|
18
|
+
|
19
|
+
class ViewController: UIViewController,LoginButtonDelegate {
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
let fbLoginButton:FBLoginButton = FBLoginButton()
|
24
|
+
var displayName = String()
|
25
|
+
var pictureURL = String()
|
26
|
+
var pictureURLString = String()
|
27
|
+
|
28
|
+
|
29
|
+
override func viewDidLoad() {
|
30
|
+
super.viewDidLoad()
|
31
|
+
|
32
|
+
fbLoginButton.delegate = self
|
33
|
+
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)
|
34
|
+
fbLoginButton.permissions = ["public_profile,email"]
|
35
|
+
view.addSubview(fbLoginButton)
|
36
|
+
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
override func viewWillAppear(_ animated: Bool) {
|
42
|
+
super.viewWillAppear(animated)
|
43
|
+
|
44
|
+
navigationController?.isNavigationBarHidden = true
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) {
|
52
|
+
|
53
|
+
if error == nil{
|
54
|
+
|
55
|
+
if result?.isCancelled == true{
|
56
|
+
|
57
|
+
return
|
58
|
+
}
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)
|
64
|
+
Auth.auth().signIn(with: credential) { (result, error) in
|
65
|
+
|
66
|
+
if let error = error{
|
67
|
+
|
68
|
+
return
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
self.displayName = result!.user.displayName!
|
73
|
+
self.pictureURLString = result!.user.photoURL!.absoluteString
|
74
|
+
self.pictureURLString = self.pictureURLString + "?type=large"
|
75
|
+
UserDefaults.standard.set(1, forKey: "loginOK")
|
76
|
+
UserDefaults.standard.set(self.displayName, forKey: "displayName")
|
77
|
+
UserDefaults.standard.set(self.pictureURLString, forKey: "pictureURLString")
|
78
|
+
|
79
|
+
let nextVC = self.storyboard?.instantiateViewController(identifier: "next") as! NextViewController
|
80
|
+
|
81
|
+
self.navigationController?.pushViewController(nextVC, animated: true)
|
82
|
+
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
func loginButtonWillLogin(_ loginButton: FBLoginButton) -> Bool {
|
92
|
+
|
93
|
+
return true
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
|
100
|
+
print("ログアウトしました!")
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```NextViewController
|
112
|
+
import UIKit
|
113
|
+
import SDWebImage
|
114
|
+
|
115
|
+
class NextViewController: UIViewController {
|
116
|
+
|
117
|
+
@IBOutlet weak var profileImageView: UIImageView!
|
118
|
+
|
119
|
+
|
120
|
+
@IBOutlet weak var userNameLabel: UILabel!
|
121
|
+
|
122
|
+
override func viewDidLoad() {
|
123
|
+
super.viewDidLoad()
|
124
|
+
|
125
|
+
if UserDefaults.standard.object(forKey: "pictureURLString") != nil || (UserDefaults.standard.object(forKey: "displayName") != nil){
|
126
|
+
|
127
|
+
let imageString = UserDefaults.standard.object(forKey: "pictureURLString") as! String
|
128
|
+
|
129
|
+
profileImageView.sd_setImage(with: URL(string: imageString), completed: nil)
|
130
|
+
|
131
|
+
profileImageView.layer.cornerRadius = 20.0
|
132
|
+
|
133
|
+
let displayName = UserDefaults.standard.object(forKey: "displayName") as! String
|
134
|
+
|
135
|
+
userNameLabel.text = displayName
|
136
|
+
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
// Do any additional setup after loading the view.
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
override func viewWillAppear(_ animated: Bool) {
|
146
|
+
super.viewWillAppear(animated)
|
147
|
+
|
148
|
+
navigationController?.isNavigationBarHidden = true
|
149
|
+
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
// MARK: - Navigation
|
154
|
+
|
155
|
+
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
156
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
157
|
+
// Get the new view controller using segue.destination.
|
158
|
+
// Pass the selected object to the new view controller.
|
159
|
+
}
|
160
|
+
*/
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
```
|