質問編集履歴
4
本文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -55,4 +55,4 @@
|
|
55
55
|
|
56
56
|
```
|
57
57
|
|
58
|
-
[参考](https://watchcontents.com/swift-appdelegate-method/)
|
58
|
+
[参考ページ](https://watchcontents.com/swift-appdelegate-method/)
|
3
本文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,4 +53,6 @@
|
|
53
53
|
}
|
54
54
|
}
|
55
55
|
|
56
|
-
```
|
56
|
+
```
|
57
|
+
|
58
|
+
[参考](https://watchcontents.com/swift-appdelegate-method/)
|
2
本文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
appDelegateからHomeViewControllerのメソッド```
|
1
|
+
appDelegateからHomeViewControllerのメソッド```hello()```を呼び出そうとしたところ
|
2
2
|
こちらのエラーが表示されアプリが落ちてしまいます。
|
3
3
|
```
|
4
4
|
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
|
1
本文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
AppDelegate
|
10
10
|
```
|
11
11
|
import UIKit
|
12
|
-
import NCMB
|
13
|
-
import AuthenticationServices
|
14
12
|
|
15
13
|
@UIApplicationMain
|
16
14
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
@@ -22,49 +20,11 @@
|
|
22
20
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
23
21
|
// Override point for customization after application launch.
|
24
22
|
|
25
|
-
// APIキー
|
26
|
-
let applicationKey = "~~~"
|
27
|
-
let clientKey = "~~~"
|
28
|
-
|
29
|
-
// APIキーの設定とSDK初期化
|
30
|
-
NCMB.initialize(applicationKey: applicationKey, clientKey: clientKey);
|
31
|
-
|
32
|
-
// on the initial view controller or somewhere else, check the userdefaults
|
33
|
-
if let userID = UserDefaults.standard.string(forKey: "userID") {
|
34
|
-
// move to main view
|
35
|
-
print("以前にログイン済み")
|
36
|
-
print(userID)
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
40
|
-
|
24
|
+
appDelegate.homeViewController.hello()//ここでエラー表示される落ちる
|
41
|
-
|
42
|
-
|
43
|
-
|
25
|
+
|
44
|
-
goLoginViewConroller()
|
45
|
-
}
|
46
|
-
|
47
26
|
return true
|
48
|
-
}
|
27
|
+
}
|
49
|
-
|
50
|
-
//ログインコントローラーに遷移
|
51
|
-
func goLoginViewConroller(){
|
52
|
-
|
53
|
-
DispatchQueue.main.async {
|
54
|
-
//画面遷移させたい部分に以下の処理を記述
|
55
|
-
// windowを生成
|
56
|
-
self.window = UIWindow(frame: UIScreen.main.bounds)
|
57
|
-
// Storyboardを指定
|
58
|
-
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
59
|
-
// Viewcontrollerを指定
|
60
|
-
let loginViewController = storyboard.instantiateViewController(withIdentifier:"login")
|
61
|
-
// rootViewControllerに入れる
|
62
|
-
self.window?.rootViewController = loginViewController
|
63
|
-
// 表示
|
64
|
-
self.window?.makeKeyAndVisible()
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
28
|
}
|
69
29
|
|
70
30
|
|
@@ -73,7 +33,6 @@
|
|
73
33
|
HomeViewController
|
74
34
|
```
|
75
35
|
import UIKit
|
76
|
-
import AuthenticationServices
|
77
36
|
|
78
37
|
|
79
38
|
class HomeViewController: UIViewController {
|
@@ -89,37 +48,9 @@
|
|
89
48
|
|
90
49
|
}
|
91
50
|
|
51
|
+
func hello() {
|
92
|
-
|
52
|
+
print("hello")
|
93
|
-
|
94
|
-
NotificationCenter.default.addObserver(self, selector: #selector(handleASCredential), name: ASAuthorizationAppleIDProvider.credentialRevokedNotification, object: nil)
|
95
|
-
|
96
|
-
|
97
53
|
}
|
98
|
-
|
99
|
-
//Appleのサインイン状態の確認
|
100
|
-
@objc func handleASCredential() {
|
101
|
-
let userID = UserDefaults.standard.string(forKey: "userID")
|
102
|
-
print("userIdは(userID)")
|
103
|
-
let appleIDProvider = ASAuthorizationAppleIDProvider()
|
104
|
-
appleIDProvider.getCredentialState(forUserID: userID!) { (credentialState, error) in
|
105
|
-
switch credentialState {
|
106
|
-
case .authorized:
|
107
|
-
print("user remain logged in, proceed to another view")
|
108
|
-
//self.performSegue(withIdentifier: "LoginToUserSegue", sender: nil)
|
109
|
-
case .revoked:
|
110
|
-
print("user logged in before but revoked")
|
111
|
-
self.appDelegate.goLoginViewConroller()
|
112
|
-
case .notFound:
|
113
|
-
print("user haven't log in before")
|
114
|
-
self.appDelegate.goLoginViewConroller()
|
115
|
-
default:
|
116
|
-
print("unknown state")
|
117
|
-
self.appDelegate.goLoginViewConroller()
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
|
123
54
|
}
|
124
55
|
|
125
56
|
```
|