Firebase Cloud Messaging (FCM): Pemberitahuan Tidak Diterima Apabila Apl Dalam Mod Latar Belakang pada iOS
FCM membenarkan pembangun menghantar pemberitahuan tolak kepada peranti iOS dan Android. Isu ini berlaku apabila pemberitahuan tidak diterima apabila apl berada di latar belakang.
Punca Kemungkinan:
Penyelesaian:
Kod PHP:
Tambahkan medan berikut pada muatan PHP anda:
Aplikasi iOS:
Kod PHP yang dikemas kini :
<code class="php"><?php $data = array( 'message' => 'Hello World!', 'body' => 'Hello World!' ); $post = array( 'registration_ids' => $ids, 'data' => $data, 'content_available' => true, 'priority' => 'high', 'notification' => $data ); // ... Remaining code</code>
Aplikasi iOS yang dikemas kini:
<code class="objc">// AppDelegate.h @interface AppDelegate : UIResponder <UIApplicationDelegate, GCMReceiverDelegate> // AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ... // Register for remote notifications if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { UIRemoteNotificationType allNotificationTypes = (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge); [application registerForRemoteNotificationTypes:allNotificationTypes]; } else { UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } // ... } - (void)applicationDidEnterBackground:(UIApplication *)application { [[GCMService sharedInstance] disconnect]; _connectedToGCM = NO; } - (void)applicationDidBecomeActive:(UIApplication *)application { [[GCMService sharedInstance] connectWithHandler:^(NSError *error) { // ... }]; } // ...</code>
Nota:
Atas ialah kandungan terperinci Mengapa Pemberitahuan Firebase Cloud Messaging (FCM) Tidak Dikekalkan dalam Mod Latar Belakang pada iOS?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!