###前提・実現したいこと
初めて質問させていただきます。
iOSアプリ開発を始めて1ヶ月半の初心者です。
iOS11をインストールした端末(iPhone SE)に
FirebaseからのリモートPush通知を受け取る機能をアプリに実装したいと思い、
Qiitaのこちらの記事を参考に準備を進めました。
https://qiita.com/jiiikki/items/31f294cf2afcfe8d868d
Podのインストールと、FirebaseへのAPNs証明書のアップロード、
プロビジョニングプロファイルのインストールまでは問題なく完了できたのですが、
最後のXcodeでプロジェクトの編集をする段階でつまづいています。
上記参考ページのコードではビルドできなかったため、
ご指導いただいている方から教えていただいた
後述するコードに変更したらビルドに成功したので、
実機でプッシュ通知を受け取ろうとテストしたところ、
通知を受け取ることができませんでした。
最近Firebase側で大規模なアップデートがあったと聞いたので、
それに関連してコードの仕様が変更になったのかと思ったのですが…
通知が受け取れない原因がいまいち特定できません。
Firebaseの仕様の変更後で、
iOS11の端末にFirebaseからのリモートPush通知を受け取るための
必要な最新のソースコードをご存知の方がいらっしゃいましたら、
ご教授いただけると幸いです。
どうぞ宜しくお願いいたします。
###【更新】該当のソースコード
Swift
1import UIKit 2import UserNotifications 3 4import Firebase 5 6@UIApplicationMain 7class AppDelegate: UIResponder, UIApplicationDelegate { 8 9 var window: UIWindow? 10 let gcmMessageIDKey = "gcm.message_id" 11 12 func application(_ application: UIApplication, 13 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 14 15 FirebaseApp.configure() 16 17 // [START set_messaging_delegate] 18 Messaging.messaging().delegate = self 19 // [END set_messaging_delegate] 20 // Register for remote notifications. This shows a permission dialog on first run, to 21 // show the dialog at a more appropriate time move this registration accordingly. 22 // [START register_for_notifications] 23 if #available(iOS 10.0, *) { 24 // For iOS 10 display notification (sent via APNS) 25 UNUserNotificationCenter.current().delegate = self 26 27 let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] 28 UNUserNotificationCenter.current().requestAuthorization( 29 options: authOptions, 30 completionHandler: {_, _ in }) 31 } else { 32 let settings: UIUserNotificationSettings = 33 UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 34 application.registerUserNotificationSettings(settings) 35 } 36 37 application.registerForRemoteNotifications() 38 39 // [END register_for_notifications] 40 return true 41 } 42 43 // [START receive_message] 44 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 45 // If you are receiving a notification message while your app is in the background, 46 // this callback will not be fired till the user taps on the notification launching the application. 47 // TODO: Handle data of notification 48 // With swizzling disabled you must let Messaging know about the message, for Analytics 49 // Messaging.messaging().appDidReceiveMessage(userInfo) 50 // Print message ID. 51 if let messageID = userInfo[gcmMessageIDKey] { 52 print("Message ID: \(messageID)") 53 } 54 55 // Print full message. 56 print(userInfo) 57 } 58 59 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], 60 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 61 // If you are receiving a notification message while your app is in the background, 62 // this callback will not be fired till the user taps on the notification launching the application. 63 // TODO: Handle data of notification 64 // With swizzling disabled you must let Messaging know about the message, for Analytics 65 // Messaging.messaging().appDidReceiveMessage(userInfo) 66 // Print message ID. 67 if let messageID = userInfo[gcmMessageIDKey] { 68 print("Message ID: \(messageID)") 69 } 70 71 // Print full message. 72 print(userInfo) 73 74 completionHandler(UIBackgroundFetchResult.newData) 75 } 76 // [END receive_message] 77 func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 78 print("Unable to register for remote notifications: \(error.localizedDescription)") 79 } 80 81 // This function is added here only for debugging purposes, and can be removed if swizzling is enabled. 82 // If swizzling is disabled then this function must be implemented so that the APNs token can be paired to 83 // the FCM registration token. 84 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 85 print("APNs token retrieved: \(deviceToken)") 86 87 // With swizzling disabled you must set the APNs token here. 88 // Messaging.messaging().apnsToken = deviceToken 89 } 90} 91 92// [START ios_10_message_handling] 93@available(iOS 10, *) 94extension AppDelegate : UNUserNotificationCenterDelegate { 95 96 // Receive displayed notifications for iOS 10 devices. 97 func userNotificationCenter(_ center: UNUserNotificationCenter, 98 willPresent notification: UNNotification, 99 withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 100 let userInfo = notification.request.content.userInfo 101 102 // With swizzling disabled you must let Messaging know about the message, for Analytics 103 // Messaging.messaging().appDidReceiveMessage(userInfo) 104 // Print message ID. 105 if let messageID = userInfo[gcmMessageIDKey] { 106 print("Message ID: \(messageID)") 107 } 108 109 // Print full message. 110 print(userInfo) 111 112 // Change this to your preferred presentation option 113 completionHandler([]) 114 } 115 116 func userNotificationCenter(_ center: UNUserNotificationCenter, 117 didReceive response: UNNotificationResponse, 118 withCompletionHandler completionHandler: @escaping () -> Void) { 119 let userInfo = response.notification.request.content.userInfo 120 // Print message ID. 121 if let messageID = userInfo[gcmMessageIDKey] { 122 print("Message ID: \(messageID)") 123 } 124 125 // Print full message. 126 print(userInfo) 127 128 completionHandler() 129 } 130} 131// [END ios_10_message_handling] 132 133extension AppDelegate : MessagingDelegate { 134 // [START refresh_token] 135 func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { 136 print("Firebase registration token: \(fcmToken)") 137 } 138 // [END refresh_token] 139 // [START ios_10_data_message] 140 // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground. 141 // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true. 142 func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { 143 print("Received data message: \(remoteMessage.appData)") 144 } 145 // [END ios_10_data_message] 146}
###【更新】試したこと
・Firebase公式ガイドに記載されている手順の通りにコードを記述した。
https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja
・上記公式ガイドにリンク付けされているGitHubのページ記載のクイックスタートをAppDelegateに丸ごとコピペしてみた。
https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55
しかし、いずれもうまくいかず、以下のようなエラーがコンソールに出る。
###【更新】発生している問題・エラーメッセージ
実機テストでFirebaseからのリモートPush通知を受け取れない。
Swift
12017-09-22 15:55:59.494542+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'. 22017-09-22 15:55:59.494 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'. 32017-09-22 15:55:59.495386+0900 Swift4RemotePushTest1[4966:1766557] [Firebase/Core][I-COR000005] No app has been configured yet. 42017-09-22 15:55:59.495 Swift4RemotePushTest1[4966] <Error> [Firebase/Core][I-COR000005] No app has been configured yet. 52017-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/.' 6*** First throw call stack: 7(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) 8libc++abi.dylib: terminating with uncaught exception of type NSException 9(lldb)
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境は以下の通りです。
macOS Sierra(10.12.6)
iOS 11.0
Xcode 9.0
Swift 4.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/22 06:56 編集
2017/09/22 06:46
2017/09/22 07:22
2017/09/22 07:30
2017/09/22 07:46
2017/09/22 07:52 編集
2017/09/22 08:11