Récemment, google a annoncé le nouveau SDK Firebase avec beaucoup plus de fonctionnalités. Donc, je suis à la search de la documentation parfaite de Comment mettre en œuvre la fonction de notification à distance en utilisant le nouveau SDK Firebase Messaging (FCM) dans iOS.
Merci beaucoup d'avance.
Première lecture de Firebase Doc. => Firebase Doc
Enregistrez le projet sur Firebase ici => Enregistrez le projet ici
Obtenez le file GoogleService-Info.plist d'ici => project => settings => General
GoogleService-Info.plist déposer votre projet.
set Notification .p12 Certificats (Production et Développement) dans Firebase => project => settings => Cloud Messaging
Télécharger Firebase SDK ici => Firebase SDK Télécharger
Créez un dossier SDK dans votre projet et supprimez tout le dossier SDK.
Maintenant, ajoutez ce Framework dans votre Xcode => libicucore.tbd
- Définir les modes d'arrière-plan ON dans Xcode => Projects => Capabilities => Mode d'arrière-plan ON => RemoteNotification
En Objective-c votre file Appdelegate.m
#import "AppDelegate.h" #import "Firebase.h" #import "AFNHelper.h" @interface AppDelegate (){ NSSsortingng *InstanceID; } @property (nonatomic, strong) NSSsortingng *strUUID; @property (nonatomic, strong) NSSsortingng *strDeviceToken; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; [FIRApp configure]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil]; return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); [[FIRMessaging messaging] appDidReceiveMessage:userInfo]; NSLog(@"userInfo=>%@", userInfo); } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; NSLog(@"deviceToken1 = %@",deviceToken); } - (void)tokenRefreshNotification:(NSNotification *)notification { NSLog(@"instanceId_notification=>%@",[notification object]); InstanceID = [NSSsortingng ssortingngWithFormat:@"%@",[notification object]]; [self connectToFcm]; } - (void)connectToFcm { [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) { if (error != nil) { NSLog(@"Unable to connect to FCM. %@", error); } else { // you can send your token here with api or etc.... } }