Copied To Clipboard

Notification Service Extension

  1. In Xcode, select File >> New >> Target and choose the Notification Service Extension template.
  2. Define a name for the Notification Service Extension as given below
  3. Objective C

    Swift code

  4. Once the target is created, Activate the scheme for Extension when prompted for the same. After this your extension will be added to project you will see a class with the extension name provided by you while creation and .plist file associated with it.
  5. Objective C

    Swift code

  6. You can configure the plist via source code or editor

Source Code

Right Click on Info.plist and click on Open as >> Source code.Add the following code in it.

  • iOS

        <key>App Bundle identifier</key>
            <string>”Your App’s Project Identifier Name”</string>
        <key>NSExtension</key>
	<dict>
		<key>NSExtensionAttributes</key>
		<dict>
			<key>UNNotificationExtensionDefaultContentHidden</key>
			<true/>
			<key>UNNotificationExtensionInitialContentSizeRatio</key>
			<real>0.7</real>
		</dict>
		<key>NSExtensionPointIdentifier</key>
		<string>com.apple.usernotifications.service</string>
		<key>NSExtensionPrincipalClass</key>
		<string>NotificationService</string>
	</dict>
       
            

Editor

Add the following keys with their required values

  • Add a new row by going to the menu and clicking Editor > Add Item. Set a key App Bundle identifier as a String and set its value to your app’s Bundle Identifier.

  • Expand the NSExtension and add NSExtensionAttributes as Dictionary. Inside NSExtensionAttributes dictionary add two keys : UNNotificationExtensionDefaultContentHidden as Boolean, its value should be YES and UNNotificationExtensionInitialContentSizeRatio as Number, its value should be 0.7
  1. Goto Build Phase tab of your Notification Service Extension target and click on “+” sign under Link Binary With Libraries. Then, click on “Add Other…” from promoted box and add the reference of our sdk .a file from your apps project folder (Don’t give reference of .a file from outside of your project).
  2. Goto NotificationService.m file and update didReceiveRequestWithContentHandler delegate mehod as follows
  • Objective C
  • Swift Code

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

            override func didReceive(_ request: UNNotificationRequest,
             withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
             self.contentHandler = contentHandler
             bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
             notifyvisitors.LoadAttachmentWithRequest(request, bestAttemptContent: self!.bestAttemptContent,
             withContentHandler: self!.contentHandler) 
             }