質問編集履歴

2

該当のソースコード、発生している問題を更新

2017/09/22 07:20

投稿

alan-d-haller
alan-d-haller

スコア18

test CHANGED
File without changes
test CHANGED
@@ -60,124 +60,360 @@
60
60
 
61
61
 
62
62
 
63
- ###発生している問題・エラメッセ
63
+ ###【更新】該当のソスコ
64
+
65
+ ```Swift
66
+
67
+ import UIKit
68
+
69
+ import UserNotifications
70
+
71
+
72
+
73
+ import Firebase
74
+
75
+
76
+
77
+ @UIApplicationMain
78
+
79
+ class AppDelegate: UIResponder, UIApplicationDelegate {
80
+
81
+
82
+
83
+ var window: UIWindow?
84
+
85
+ let gcmMessageIDKey = "gcm.message_id"
86
+
87
+
88
+
89
+ func application(_ application: UIApplication,
90
+
91
+ didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
92
+
93
+
94
+
95
+ FirebaseApp.configure()
96
+
97
+
98
+
99
+ // [START set_messaging_delegate]
100
+
101
+ Messaging.messaging().delegate = self
102
+
103
+ // [END set_messaging_delegate]
104
+
105
+ // Register for remote notifications. This shows a permission dialog on first run, to
106
+
107
+ // show the dialog at a more appropriate time move this registration accordingly.
108
+
109
+ // [START register_for_notifications]
110
+
111
+ if #available(iOS 10.0, *) {
112
+
113
+ // For iOS 10 display notification (sent via APNS)
114
+
115
+ UNUserNotificationCenter.current().delegate = self
116
+
117
+
118
+
119
+ let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
120
+
121
+ UNUserNotificationCenter.current().requestAuthorization(
122
+
123
+ options: authOptions,
124
+
125
+ completionHandler: {_, _ in })
126
+
127
+ } else {
128
+
129
+ let settings: UIUserNotificationSettings =
130
+
131
+ UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
132
+
133
+ application.registerUserNotificationSettings(settings)
134
+
135
+ }
136
+
137
+
138
+
139
+ application.registerForRemoteNotifications()
140
+
141
+
142
+
143
+ // [END register_for_notifications]
144
+
145
+ return true
146
+
147
+ }
148
+
149
+
150
+
151
+ // [START receive_message]
152
+
153
+ func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
154
+
155
+ // If you are receiving a notification message while your app is in the background,
156
+
157
+ // this callback will not be fired till the user taps on the notification launching the application.
158
+
159
+ // TODO: Handle data of notification
160
+
161
+ // With swizzling disabled you must let Messaging know about the message, for Analytics
162
+
163
+ // Messaging.messaging().appDidReceiveMessage(userInfo)
164
+
165
+ // Print message ID.
166
+
167
+ if let messageID = userInfo[gcmMessageIDKey] {
168
+
169
+ print("Message ID: \(messageID)")
170
+
171
+ }
172
+
173
+
174
+
175
+ // Print full message.
176
+
177
+ print(userInfo)
178
+
179
+ }
180
+
181
+
182
+
183
+ func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
184
+
185
+ fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
186
+
187
+ // If you are receiving a notification message while your app is in the background,
188
+
189
+ // this callback will not be fired till the user taps on the notification launching the application.
190
+
191
+ // TODO: Handle data of notification
192
+
193
+ // With swizzling disabled you must let Messaging know about the message, for Analytics
194
+
195
+ // Messaging.messaging().appDidReceiveMessage(userInfo)
196
+
197
+ // Print message ID.
198
+
199
+ if let messageID = userInfo[gcmMessageIDKey] {
200
+
201
+ print("Message ID: \(messageID)")
202
+
203
+ }
204
+
205
+
206
+
207
+ // Print full message.
208
+
209
+ print(userInfo)
210
+
211
+
212
+
213
+ completionHandler(UIBackgroundFetchResult.newData)
214
+
215
+ }
216
+
217
+ // [END receive_message]
218
+
219
+ func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
220
+
221
+ print("Unable to register for remote notifications: \(error.localizedDescription)")
222
+
223
+ }
224
+
225
+
226
+
227
+ // This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
228
+
229
+ // If swizzling is disabled then this function must be implemented so that the APNs token can be paired to
230
+
231
+ // the FCM registration token.
232
+
233
+ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
234
+
235
+ print("APNs token retrieved: \(deviceToken)")
236
+
237
+
238
+
239
+ // With swizzling disabled you must set the APNs token here.
240
+
241
+ // Messaging.messaging().apnsToken = deviceToken
242
+
243
+ }
244
+
245
+ }
246
+
247
+
248
+
249
+ // [START ios_10_message_handling]
250
+
251
+ @available(iOS 10, *)
252
+
253
+ extension AppDelegate : UNUserNotificationCenterDelegate {
254
+
255
+
256
+
257
+ // Receive displayed notifications for iOS 10 devices.
258
+
259
+ func userNotificationCenter(_ center: UNUserNotificationCenter,
260
+
261
+ willPresent notification: UNNotification,
262
+
263
+ withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
264
+
265
+ let userInfo = notification.request.content.userInfo
266
+
267
+
268
+
269
+ // With swizzling disabled you must let Messaging know about the message, for Analytics
270
+
271
+ // Messaging.messaging().appDidReceiveMessage(userInfo)
272
+
273
+ // Print message ID.
274
+
275
+ if let messageID = userInfo[gcmMessageIDKey] {
276
+
277
+ print("Message ID: \(messageID)")
278
+
279
+ }
280
+
281
+
282
+
283
+ // Print full message.
284
+
285
+ print(userInfo)
286
+
287
+
288
+
289
+ // Change this to your preferred presentation option
290
+
291
+ completionHandler([])
292
+
293
+ }
294
+
295
+
296
+
297
+ func userNotificationCenter(_ center: UNUserNotificationCenter,
298
+
299
+ didReceive response: UNNotificationResponse,
300
+
301
+ withCompletionHandler completionHandler: @escaping () -> Void) {
302
+
303
+ let userInfo = response.notification.request.content.userInfo
304
+
305
+ // Print message ID.
306
+
307
+ if let messageID = userInfo[gcmMessageIDKey] {
308
+
309
+ print("Message ID: \(messageID)")
310
+
311
+ }
312
+
313
+
314
+
315
+ // Print full message.
316
+
317
+ print(userInfo)
318
+
319
+
320
+
321
+ completionHandler()
322
+
323
+ }
324
+
325
+ }
326
+
327
+ // [END ios_10_message_handling]
328
+
329
+
330
+
331
+ extension AppDelegate : MessagingDelegate {
332
+
333
+ // [START refresh_token]
334
+
335
+ func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
336
+
337
+ print("Firebase registration token: \(fcmToken)")
338
+
339
+ }
340
+
341
+ // [END refresh_token]
342
+
343
+ // [START ios_10_data_message]
344
+
345
+ // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
346
+
347
+ // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
348
+
349
+ func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
350
+
351
+ print("Received data message: \(remoteMessage.appData)")
352
+
353
+ }
354
+
355
+ // [END ios_10_data_message]
356
+
357
+ }
358
+
359
+ ```
360
+
361
+
362
+
363
+ ###【更新】試したこと
364
+
365
+
366
+
367
+ ・Firebase公式ガイドに記載されている手順の通りにコードを記述した。
368
+
369
+ [https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja](https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja)
370
+
371
+
372
+
373
+ ・上記公式ガイドにリンク付けされているGitHubのページ記載のクイックスタートをAppDelegateに丸ごとコピペしてみた。
374
+
375
+ [https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55](https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55)
376
+
377
+
378
+
379
+ しかし、いずれもうまくいかず、以下のようなエラーがコンソールに出る。
380
+
381
+
382
+
383
+ ###【更新】発生している問題・エラーメッセージ
64
384
 
65
385
  実機テストでFirebaseからのリモートPush通知を受け取れない。
66
386
 
67
387
 
68
388
 
69
-
70
-
71
- ###該当のソスコード
389
+ ![イメジ説明](5d51dc564dcc463f022c6fc1482f322c.png)
390
+
391
+
72
392
 
73
393
  ```Swift
74
394
 
75
- import UIKit
76
-
77
- import Firebase
78
-
79
- import UserNotifications
80
-
81
-
82
-
83
- @UIApplicationMain
84
-
85
- class AppDelegate: UIResponder, UIApplicationDelegate {
86
-
87
-
88
-
89
- var window: UIWindow?
90
-
91
-
92
-
93
-
94
-
95
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
96
-
97
-
98
-
99
- let center = UNUserNotificationCenter.current()
100
-
101
- //get the notification center
102
-
103
- center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
104
-
105
- // Enable or disable features based on authorization.
106
-
107
-
108
-
109
- }
110
-
111
-
112
-
113
- FirebaseApp.configure()
114
-
115
-
116
-
117
- return true
118
-
119
- }
120
-
121
-
122
-
123
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){
124
-
125
-
126
-
127
- InstanceID.instanceID().setAPNSToken(deviceToken as Data, type: InstanceIDAPNSTokenType.unknown)
128
-
129
-
130
-
131
- }
395
+ 2017-09-22 15:55:59.494542+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
396
+
397
+ 2017-09-22 15:55:59.494 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
398
+
399
+ 2017-09-22 15:55:59.495386+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000005] No app has been configured yet.
400
+
401
+ 2017-09-22 15:55:59.495 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000005] No app has been configured yet.
402
+
403
+ 2017-09-22 15:55:59.502100+0900 Swift4RemotePushTest1[4966:1766494] *** Terminating app due to uncaught exception 'com.firebase.core', reason: '`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
404
+
405
+ *** First throw call stack:
406
+
407
+ (0x183f1bd38 0x183430528 0x183f1bc80 0x1025b5830 0x102550c64 0x1025516d0 0x18d39a050 0x18d58d898 0x18d5926e4 0x18d820454 0x18daf01f0 0x18d8200b8 0x18d820928 0x18df896e8 0x18df8958c 0x18dd059c0 0x18de9afc8 0x18dd05870 0x18daef850 0x18d590e28 0x18d9946ec 0x1865bd768 0x1865c6070 0x1036f145c 0x1036fdb74 0x1865f1a04 0x1865f16a8 0x1865f1c44 0x183ec4358 0x183ec42d8 0x183ec3b60 0x183ec1738 0x183de22d8 0x185c73f84 0x18d38e880 0x1025542cc 0x18390656c)
408
+
409
+ libc++abi.dylib: terminating with uncaught exception of type NSException
410
+
411
+ (lldb)
132
412
 
133
413
  ```
134
414
 
135
415
 
136
416
 
137
- ###【更新】試したこと
138
-
139
-
140
-
141
- ・Firebase公式ガイドに記載されている手順の通りにコードを記述した。
142
-
143
- [https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja](https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja)
144
-
145
-
146
-
147
- ・上記公式ガイドにリンク付けされているGitHubのページ記載のクイックスタートをAppDelegateに丸ごとコピペしてみた。
148
-
149
- [https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55](https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55)
150
-
151
-
152
-
153
- しかし、いずれもうまくいかず、以下のようなエラーがコンソールに出る。
154
-
155
-
156
-
157
- ```Swift
158
-
159
- 2017-09-22 15:55:59.494542+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
160
-
161
- 2017-09-22 15:55:59.494 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
162
-
163
- 2017-09-22 15:55:59.495386+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000005] No app has been configured yet.
164
-
165
- 2017-09-22 15:55:59.495 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000005] No app has been configured yet.
166
-
167
- 2017-09-22 15:55:59.502100+0900 Swift4RemotePushTest1[4966:1766494] *** Terminating app due to uncaught exception 'com.firebase.core', reason: '`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
168
-
169
- *** First throw call stack:
170
-
171
- (0x183f1bd38 0x183430528 0x183f1bc80 0x1025b5830 0x102550c64 0x1025516d0 0x18d39a050 0x18d58d898 0x18d5926e4 0x18d820454 0x18daf01f0 0x18d8200b8 0x18d820928 0x18df896e8 0x18df8958c 0x18dd059c0 0x18de9afc8 0x18dd05870 0x18daef850 0x18d590e28 0x18d9946ec 0x1865bd768 0x1865c6070 0x1036f145c 0x1036fdb74 0x1865f1a04 0x1865f16a8 0x1865f1c44 0x183ec4358 0x183ec42d8 0x183ec3b60 0x183ec1738 0x183de22d8 0x185c73f84 0x18d38e880 0x1025542cc 0x18390656c)
172
-
173
- libc++abi.dylib: terminating with uncaught exception of type NSException
174
-
175
- (lldb)
176
-
177
- ```
178
-
179
-
180
-
181
417
 
182
418
 
183
419
  ###補足情報(言語/FW/ツール等のバージョンなど)

1

試したことの内容を更新しました。

2017/09/22 07:20

投稿

alan-d-haller
alan-d-haller

スコア18

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  Podのインストールと、FirebaseへのAPNs証明書のアップロード、
20
20
 
21
- プロビジョニングファイルのインストールまでは問題なく完了できたのですが、
21
+ プロビジョニングプロファイルのインストールまでは問題なく完了できたのですが、
22
22
 
23
23
  最後のXcodeでプロジェクトの編集をする段階でつまづいています。
24
24
 
@@ -134,9 +134,47 @@
134
134
 
135
135
 
136
136
 
137
- ###試したこと
137
+ ###【更新】試したこと
138
138
 
139
- ・Qiitaの参考ページに記載のコードではビルドできなかったため、ご指導いただいている方から教えていただいた上記コードに変更した。
139
+
140
+
141
+ ・Firebase公式ガイドに記載されている手順の通りにコードを記述した。
142
+
143
+ [https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja](https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja)
144
+
145
+
146
+
147
+ ・上記公式ガイドにリンク付けされているGitHubのページ記載のクイックスタートをAppDelegateに丸ごとコピペしてみた。
148
+
149
+ [https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55](https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55)
150
+
151
+
152
+
153
+ しかし、いずれもうまくいかず、以下のようなエラーがコンソールに出る。
154
+
155
+
156
+
157
+ ```Swift
158
+
159
+ 2017-09-22 15:55:59.494542+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
160
+
161
+ 2017-09-22 15:55:59.494 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
162
+
163
+ 2017-09-22 15:55:59.495386+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000005] No app has been configured yet.
164
+
165
+ 2017-09-22 15:55:59.495 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000005] No app has been configured yet.
166
+
167
+ 2017-09-22 15:55:59.502100+0900 Swift4RemotePushTest1[4966:1766494] *** Terminating app due to uncaught exception 'com.firebase.core', reason: '`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
168
+
169
+ *** First throw call stack:
170
+
171
+ (0x183f1bd38 0x183430528 0x183f1bc80 0x1025b5830 0x102550c64 0x1025516d0 0x18d39a050 0x18d58d898 0x18d5926e4 0x18d820454 0x18daf01f0 0x18d8200b8 0x18d820928 0x18df896e8 0x18df8958c 0x18dd059c0 0x18de9afc8 0x18dd05870 0x18daef850 0x18d590e28 0x18d9946ec 0x1865bd768 0x1865c6070 0x1036f145c 0x1036fdb74 0x1865f1a04 0x1865f16a8 0x1865f1c44 0x183ec4358 0x183ec42d8 0x183ec3b60 0x183ec1738 0x183de22d8 0x185c73f84 0x18d38e880 0x1025542cc 0x18390656c)
172
+
173
+ libc++abi.dylib: terminating with uncaught exception of type NSException
174
+
175
+ (lldb)
176
+
177
+ ```
140
178
 
141
179
 
142
180