On this Page:
...
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken");
[[EuroManager sharedManager:@"AppcentIOSTest1"] registerToken:deviceToken];
} |
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
EuroManager.sharedManager("AppcentIOSTest1").registerToken(deviceToken)
} |
In the
Status |
---|
subtle | true |
---|
colour | Red |
---|
title | application:didRegisterForRemoteNotificationsWithDeviceToken: |
---|
|
method, deviceToken variable is the generated token by APNS. After receiving this token, registerToken method is called in EuroManager. This token value must be recorded to the RMC system in order to send messages. In the example,
Status |
---|
| |
---|
subtle | true |
---|
colour | Red |
---|
title | AppcentIOSTest1 |
---|
|
value is a code value that is given by RMC for your application.
EuroManager instance is activated as shown below:
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
[[EuroManager sharedManager:@"AppcentIOSTest1"] setUserKeysetUserEmail: @"egemen@visilabs.com"];
[[EuroManager sharedManager:@"AppcentIOSTest1"] setUserEmailsetUserKey: @"egemen@visilabs.com123456789"];
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize];
|
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
let euroInstance: EuroManager = EuroManager.sharedManager("AppcentIOSTest1")
euroInstance.setUserEmail("egemen@visilabs.com")
euroInstance.setUserEmailsetUserKey("egemen@visilabs.com123456789")
euroInstance("AppcentIOSTest1").synchronize()
|
If the additional parameters of the user are known, they can be added as shown below:
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
[[EuroManager sharedManager:@"AppcentIOSTest1"] userEmail: @"egemen@visilabs.com"];
[[EuroManager sharedManager:@"AppcentIOSTest1"] setUserKey: @"egemen@visilabs.com123456789"];
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize];
|
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
let euroInstance: EuroManager = EuroManager.sharedManager("AppcentIOSTest1")
euroInstance.setUserEmail("egemen@visilabs.com")
euroInstance.setUserKey("egemen@visilabs.com123456789")
euroInstance.synchronize() |
In any step, if you add a new parameter and want to send it to the RMC server, you should call the "synchronize" method:
Use the following method when the user logs in to your mobile app:
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize]; |
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
EuroManager.sharedManager("AppcentIOSTest1").synchronize()
|
If a push notification arrives, application:didReceiveRemoteNotification method is invoked. The incoming message content should be given to the handlePush method in the EuroManager instance. This should be used for sending push open information.
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo];
} |
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]){
EuroManager.sharedManager("AppcentIOSTest1").handlePush(userInfo)
} |
If you are using iOS 8 or later version, the following method should be called:
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo];
} |
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
EuroManager.sharedManager("AppcentIOSTest1").handlePush(userInfo)
} |
Add a Notification Service Extension
- File > New > Target > Select Notification Service Extension.
- Enter the product name as Euro-IOSNotificationServiceExtension.
- Select the language you use and press the Finish button.
- Click the Cancel button in the dialog window that will open.
In the project navigator, select the top-level project directory and select the Euro-IOSNotificationServiceExtension target in the project and targets list. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 11.
- Open NotificationService.swift/NotificationService.m and replace the whole file's contents with the following code.
Code Block |
---|
language | applescript |
---|
title | Swift |
---|
|
import UserNotifications
import Euro_IOS
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
EuroManager.didReceive(bestAttemptContent, withContentHandler: contentHandler)
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
EuroManager.didReceive(bestAttemptContent, withContentHandler: contentHandler)
}
}
} |
Code Block |
---|
language | applescript |
---|
title | Objective-C |
---|
|
#import "NotificationService.h"
@import Euro_IOS;
@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];
[EuroManager didReceive:_bestAttemptContent withContentHandler:contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
[EuroManager didReceive:_bestAttemptContent withContentHandler:_contentHandler];
}
@end |
Ignore any build errors at this point, step 2 will import Euromessage which will resolve any errors.
If you have already added the Euromessage library to your project, simply add the Euro-IOSNotificationServiceExtension section.
Image Added
Variables in the Message class:
Variable | Description |
---|
messageContent | Message |
URL | An optional URL |
params | Custom parameters |
pushType | Push Type |
altURL | Alternate URL |
mediaUrl | Image and Video content URL |
cId | Campaign id |
sound | Sound name |
...