iOS Push

This document describes steps necessary to integrate iOS App with LivePinch. Here, while covering the topic of integration, we assume that you’ve already created a provisioning profile and .p12 certificates from Apple Developer

Upload Push Certificates to the Dashboard

Click on Account > iOS Push on the navigation panel

iOS Push Certificate
  • Upload the .p12 certificate obtained from Apple Developer
  • Turn the development switch if this is a development certificate
  • Optionally enter certificate passphrase, if one exists
  • Enter the package identifier, this will be used as topic for push notifications sent

Enable push and background modes capabilities

  • Enter Project Navigator view.
  • Select your main app target from the expanded sidebar or from the dropdown menu, then select the Capabilities tab.
  • Turn on Push Notification.
API Key
  • If Background Modes is not enabled, click the switch and then tick the Remote notifications checkbox. LivePinch uses background modes to track when push messages are received on a user’s device before the message is opened.

    API Key

Setup the client for push

With Swift

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
  LivePinch.getInstance().didRegisterForRemoteNotificationsWithDeviceToken(deviceTokenString)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  LivePinch.getInstance().didFailToRegisterForRemoteNotificationsWithError(error)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
  LivePinch.getInstance().didReceiveRemoteNotification(application, userInfo: userInfo)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  LivePinch.getInstance().didReceiveRemoteNotification(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
}

With Objective-C

- (void) application: (UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken: (NSData*)deviceToken
{
    NSString * deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""]   stringByReplacingOccurrencesOfString: @" " withString: @""];
    [[LivePinch getInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceTokenString];
}

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

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


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

Rich Push Notification Integration (Requires iOS 10.0 and Above)

Create Notification Service Extension

  • In Xcode, navigate to File > New > Target and select Notification Service Extension
  • Click Next, fill out the Product Name as NotificationService, and click Finish
  • Click Activate on the prompt shown to activate the service extension.

Xcode will now create a new top level folder in your project with the name NotificationService.

Add LivePinch to Notification Service Target

target 'NotificationService' do
  inherit! :search_paths
  pod 'LivePinch', '2.4'
end

Call LivePinch function inside NotificationService class, your code will be look like following

With Swift

import UserNotifications
import DeltaTrackLib

class NotificationService: UNNotificationServiceExtension {

  var contentHandler: ((UNNotificationContent) -> Void)?
  var bestAttemptContent: UNMutableNotificationContent?

  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
      LivePinch.getInstance().didReceive(request, withContentHandler: contentHandler)
  }


}

With Objective-C

@import LivePinch;

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    [[LivePinch getInstance] didReceive:request withContentHandler:contentHandler];
}

@end