iOS 10 has introduced customised push notification too by Notification content extension (app extension).
A developer needs to add an extension like we did for the Notification service extension for configuring carousel push notification, SDK support animated and non-animated push notification with carousel themes, carousel type and theme can be set inside push notification payload.
Set up Notification Content Extension
- In Xcode 8 and above File -> New -> Target
- Select Notification Content Extension , press Next
- Fill in the details in the pop-up and press Finish.(The pop-up asks you to add new schema, do it)
- It will create a new group with the name you give. You can see this in directory panel in x code.
- Select the newly created target from the project target list
- You need to configure new bundle id and provisioning profiles for app extension in Apple developer portal.
- Fill in the details in General Tab inside app extension target.
- Expand newly created group in left panel. It may contain NotificationViewController.h, NotificationViewController.m, MainInterface.storyboard and Info.plist files
- Open Info.plist file and add Application Transport Security
For example, you can add a specific domain like:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
The lazy option is:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
add NSExtensionAttributes inside NSExtension
UNNotificationExtensionCategory with array items carousel_animation
and carousel
UNNotificationExtensionInitialContentSizeRatio with value 0.7
a sample one below
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<array>
<string>carousel_animation</string>
<string>carousel</string>
</array>
<key>UNNotificationExtensionDefaultContentHidden</key>
<false/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>0.7</real>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
</dict>
Next step is need to install BlueShift-iOS-SDK pod app extension for notification content extension
target 'APP EXTENSION TARGET NAME' do
pod 'BlueShift-iOS-Extension-SDK'
end
Open MainInterface.storyboard and remove 'Hello World' UILabel
Open NotificationViewController.h and import header
#import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>
- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion {
[self setCarouselActionsForResponse:response completionHandler:^(UNNotificationContentExtensionResponseOption option) {
completion(option);
}];
}
The file looks like
@implementation NotificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any required interface initialization here.
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)didReceiveNotification:(UNNotification *)notification {
[self showCarouselForNotfication:notification];
}
- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion {
[self setCarouselActionsForResponse:response completionHandler:^(UNNotificationContentExtensionResponseOption option) {
completion(option);
}];
}
@end
Create bridge-header file for notification content extension and import
`#import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>`
class NotificationViewController: BlueShiftCarousalViewController, UNNotificationContentExtension {
override func viewDidLoad() {
super.viewDidLoad()
// Do any required interface initialization here.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
func didReceive(_ notification: UNNotification) {
showCarousel(forNotfication: notification)
}
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
setCarouselActionsFor(response) { (option) in
completion(option)
}
}
}