Notification dans iOS à l'aide du nouveau SDK Firebase Messaging

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.

Intégrer sans CocoaPods

Première lecture de Firebase Doc. => Firebase Doc

  1. Enregistrez le projet sur Firebase ici => Enregistrez le projet ici

  2. Obtenez le file GoogleService-Info.plist d'ici => project => settings => General

  3. GoogleService-Info.plist déposer votre projet.

  4. set Notification .p12 Certificats (Production et Développement) dans Firebase => project => settings => Cloud Messaging

  5. Télécharger Firebase SDK ici => Firebase SDK Télécharger

  6. Créez un dossier SDK dans votre projet et supprimez tout le dossier SDK.

  7. Maintenant, ajoutez ce Framework dans votre Xcode => libicucore.tbd

  8. Définir les modes d'arrière-plan ON dans Xcode => Projects => Capabilities => Mode d'arrière-plan ON => RemoteNotification

entrez la description de l'image ici

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.... } }