iosにてfirebaseでプッシュ通知を送りたいのですが全く送られてきません。
APNs用証明書の作成、p12ファイルの登録、アプリへのコードの追加など必要な処理は全て対応したと思うんですが割とお手上げ状態です。
ここでハマった、これはやったか?などなんか教えていただけると嬉しいです。
下記は対応した内容です。
- キーチェーンアクセスでcsrを作成
- apple developer consoleで既存のアプリにAPNs証明書を作成(さっき作成したcsrを使って開発用、本番用を作成)
- 開発用、本番用のプロビジョニングファイルを更新
- xcodeで先ほどのプロビジョニングファイルをインストール
- AppDelegate.mにコードを追加(既存のアプリへの追加ですので他のコード)
objective
1 2@import Firebase; 3@import FirebaseInstanceID; 4@import FirebaseMessaging; 5 6@implementation AppDelegate 7 8- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 9{ 10 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0f) { 11 UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 12 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 13 [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 14 [[UIApplication sharedApplication] registerForRemoteNotifications]; 15 } 16 17 [FIRApp configure]; 18 19 [[NSNotificationCenter defaultCenter] addObserver:self 20 selector:@selector(tokenRefreshNotification:) 21 name:kFIRInstanceIDTokenRefreshNotification 22 object:nil]; 23 return YES; 24} 25 26- (void)applicationDidEnterBackground:(UIApplication *)application 27{ 28 [[FIRMessaging messaging] disconnect]; 29} 30 31- (void)applicationDidBecomeActive:(UIApplication *)application 32{ 33 [self connectToFcm]; 34} 35 36- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 37#ifdef DEBUG 38 [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox]; 39#else 40 [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; 41#endif 42} 43 44// [START refresh_token] 45- (void)tokenRefreshNotification:(NSNotification *)notification { 46 [self connectToFcm]; 47} 48 49// [START connect_to_fcm] 50- (void)connectToFcm { 51 [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {}]; 52} 53 54@end 55

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。