Skip to content

Latest commit

 

History

History
124 lines (88 loc) · 3.98 KB

guide.md

File metadata and controls

124 lines (88 loc) · 3.98 KB

Setup project in Xcode

Open you project in Xcode

  • run Xcode and open you project
  • or you can do it by the next command in terminal as well
open ios/<ProjectName>.xcodeproj

Basic Setup

img

You must specify the Signing team for both targets: and Test as it shown on the image below img

Specify Bundle identifier must be the same as in your certificate

img

Enable Push Notifications compatibility img

Modify your AppDelegate.m file

Import RNBackendless library

#import <RNBackendless/RNBackendless.h>

Add the following implementation

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [RNBackendless didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RNBackendless didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RNBackendless didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNTextInputNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler
{
  [RNBackendless didReceiveNotificationResponse:response];
  
  completionHandler();
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
  [RNBackendless didReceiveRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RNBackendless didReceiveRemoteNotification:userInfo];
  
  completionHandler(UIBackgroundFetchResultNewData);
}

And add as the first line of didFinishLaunchingWithOptions implementation the next line:

[UNUserNotificationCenter currentNotificationCenter].delegate = self;

That’s enough to start receiving simple Remote Push Notification

Advanced

img img

In order to use Push Notification Templates and receive rich notifications, including images and actions you have to add a Notification Service and enable App Groups and RNBackendless will take care about your notifications

Add Notification Service Extension

img img

Add to the service React libraries and RNBackendless library

  • libRCTWebSocket.a
  • libReact.a
  • libRNBackendless.a img

And also you must add Other Linker Flags in Build Settings for the NotificationService Extension

-ObjC
$(inherited)
-lc++

img

In order to display a push notification based on a Push Notification Template need to enable App Group in Capabilities section for the extension, you can read more here

The most important thing is your group must contain BackendlessPushTemplates phrase

img img

And do the same for main target

img img

Change didReceiveNotificationRequest implementation in NotificationService.m file


- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  self.contentHandler = contentHandler;
  self.bestAttemptContent = [request.content mutableCopy];
  
  [RNBackendless processMutableContent:request withContentHandler:contentHandler];
}