iOS SDK integration

Here you can find simple way of implementing Hengam SDK using Xcode.

This guide assumes that you've already followed the prerequisites.

1. Add Notification Service Extension to your project

If you want to send rich-media push notifications (containing images, gif, video, action buttons and ...) to your users, you must follow the Add Notification Service Extension Guide.

Then, change NotificationService.m as follows:

#import "NotificationService.h"
@import Hengam;
@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 {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    [HengamClient.shared didReceiveNotificationExtensionRequest:self.bestAttemptContent :self.contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
    self.contentHandler(self.bestAttemptContent);
}
@end
import UserNotifications
import Hengam
class NotificationService: UNNotificationServiceExtension {
    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = self.bestAttemptContent {
            HengamClient.shared.didReceiveNotificationExtensionRequest(mutableContent: bestAttemptContent, contentHandler: contentHandler)
        }
    }
    override func serviceExtensionTimeWillExpire() {
        if let contentHandler = self.contentHandler, let bestAttemptContent =  self.bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }
}

2. Integrate Hengam SDK (Using CocoaPods)

To integrate Hengam SDK for iOS into your Xcode project using CocoaPods, specify it in your Podfile

target 'NOTIFICATION_SERVICE_EXTENSION_NAME' do
  use_frameworks!
    pod 'Hengam'
end
target 'PROJECT_NAME’' do
  use_frameworks!
    pod 'Hengam'
end

You can refer to the this link for more information about adding podfile to your project.

3. Update info.plist file

Add a new row to the info.plist file of your project by name = HengamAppId and value = HENGAM_TOKEN.

The value HENGAM_TOKEN is a sample. Replace it with your own token which is a unique token, available in Hengam dashboard for your app.

Test & diagnosis

Now you should:

  1. Run and install your app on a test device.
  2. Make sure your device is connected to internet.
  3. Open the app and wait until your installation is received by the hengam.

Too long? check the troubleshooting section. Your problem may be found there.

Support

If you have any problem, please contact us using this email, we will get back to you right away: hi [at] hengam.io