Panel | ||||
---|---|---|---|---|
| ||||
Click to reach documentation. |
General Information
Apple Push Notification Server (APNS) is a central server where all the iOS devices are connected at any given time. In order to send the message to the target device and application, a token is generated for each device-application pair and this token is sent to APNS along with the message.
You need to send the following information to RMC for APNS communication:
Token List
Certificate (http://developer.apple.com/membercenter)
...
APNS Methods
APNS works in two modes, Sandbox and Production:
Sandbox certificate is used for applications that are not submitted to the Appstore and generally when the app is attached to the debugger (USB cable connection to XCode).
Production certificate is used for applications distributed through ad-hoc and Testflight (closed distribution) and for applications in the appstore.
After you imported the SDK into your project by adding the related files, you can integrate the SDK using the following steps.
The following method should be used for registering the application into the APNS system:
Objective-C
Code Block | ||||
---|---|---|---|---|
| ||||
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; |
...
Swift
Code Block | ||||
---|---|---|---|---|
| ||||
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];In AppDelegate file of your project you should edit didFinishLaunchingWithOptions func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: {_, _ in }) } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } } |
After that point, the user has to accept to receive push messages. If the user accepts and the device is successfully registered to the APNS, the following method is called in AppDelegate:
Objective-C
Code Block | ||
---|---|---|
|
...
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { |
...
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken"); |
...
|
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] registerToken:deviceToken];
} |
Swift
Code Block | ||
---|---|---|
| ||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
EuroManager.sharedManager("AppcentIOSTest1").registerToken(deviceToken)
} |
In the
Status | ||||||
---|---|---|---|---|---|---|
|
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 | ||||||
---|---|---|---|---|---|---|
|
...
EuroManager instance is activated as shown below:
Objective-C
Code Block | ||
---|---|---|
|
...
- (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Registration failed : %@",error.description); }
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] setUserEmail: @"egemen@visilabs.com"];
[[EuroManager sharedManager:@"AppcentIOSTest1" setUserKey: @"123456789"];
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize];
|
Swift
Code Block | ||
---|---|---|
|
...
let euroInstance: EuroManager |
...
= |
...
EuroManager |
...
.sharedManager |
...
("AppcentIOSTest1" |
...
)
euroInstance.setUserEmail("egemen@visilabs.com")
euroInstance.setUserKey("123456789")
euroInstance("AppcentIOSTest1").synchronize()
|
If the additional parameters of the user are known, they can be added as shown below:
Objective-C
Code Block | ||
---|---|---|
|
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] userEmail: @"egemen@visilabs.com"]; |
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] setUserKey: @"123456789"]; [ |
...
[EuroManager |
...
sharedManager:@" |
...
AppcentIOSTest1"] synchronize]; |
...
|
Swift
Code Block | ||
---|---|---|
| ||
let euroInstance: EuroManager = EuroManager.sharedManager("AppcentIOSTest1")
euroInstance.setUserEmail("egemen@visilabs.com")
euroInstance.setUserKey("123456789")
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:
Objective-C
Code Block | ||
---|---|---|
| ||
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize]; |
Swift
...
Code Block | ||
---|---|---|
|
...
EuroManager.sharedManager("AppcentIOSTest1").synchronize() |
IYS Email Register
If your user is a corporate account, you must send it as a TACIR. For this, change the isCommercial parameter to true from the registerEmail method.
Objective-C
Code Block | ||
---|---|---|
| ||
void (^success)(void) = ^void(void) { NSLog(@"registerEmail sucess"); }; void (^failure)(NSString*) = ^void(NSString* message) { NSLog(@"registerEmail failure"); NSLog(@"%@", message); }; [[EuroManager sharedManager:@" |
...
EuromsgIOSTest"] |
...
registerEmail:@"test@euromsg.com" emailPermit:YES isCommercial:NO success:success failure:failure]; |
Swift
Code Block | ||
---|---|---|
| ||
let success: (() -> Void)? = {
print("registerEmail sucess")
}
let failure: ((String?) -> Void)? = { message in
print("registerEmail failure")
print("\(message ?? "")")
}
EuroManager.sharedManager("EuromsgTest")?.registerEmail("test@euromsg.com", emailPermit: true, isCommercial: false, success: success, failure: failure) |
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.
Objective-C
Code Block | ||
---|---|---|
|
...
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { |
...
|
...
|
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo];
} |
Swift
Code Block | ||
---|---|---|
| ||
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:
Objective-C
Code Block | ||
---|---|---|
|
...
- (void) |
...
application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
...
[[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo]; |
...
When an interactive push is sent, the information of which button is clicked by the user should be transmitted to RMC. For this application:
method in the Status subtle true colour Red title handleActionWithIdentifier:forRemoteNotification:completionHandler:
is called as shown below: Status subtle true colour Red title AppDelegate
...
language | applescript |
---|---|
linenumbers | true |
...
} |
Swift
Code Block | ||
---|---|---|
| ||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
EuroManager.sharedManager("AppcentIOSTest1").handlePush(userInfo)
} |
Reflection of Push Campaign Revenues to RMC Panel
After clicking the incoming push notification, you need to use the following method to reflect the purchase made in the Revenue field in the RMC panel.
You must enter utm parameters in the Custom Parameters field on the push screen.
Ex: utm_medium=apppush;utm_source=related;utm_campaign=campaign_name
P.S: Since utm_campaign should be different each time, you can use the ID of the push campaign you created as a variable. You can optionally use the <## CAMP_ID ##> variable for this.After clicking the push notification, a data will be returned to you as below.
Sample Data:
Code Block "pushId": df73706e-1138-40f2-b687-c10c43ee8138, "aps": { alert = { body = Test; title = Test; }; badge = 0; "content-available" = 0; "mutable-content" = 1; sound = ""; }, "pushType": Text, "url": , "mediaUrl": , "deepLink": , "altUrl": , "utm_campaign": campaign_name, "utm_medium": apppush, "utm_source": related
You should handle this data just like using deeplink and send the utm parameters as event to Visilabs when the push message is clicked. You can find sample Visilabs event codes on the bottom line.
Objective-C
Code Block language objective-c NSMutableDictionary *properties = [[NSMutableDictionary alloc] init]; [properties setObject:@"utm_campaign" forKey:@"campaign_name"]; [properties setObject:@"utm_source" forKey:@"related"]; [properties setObject:@"utm_medium" forKey:@"apppush"]; [properties setObject:@"KeyID or Email" forKey:@"OM.exVisitorID"]; //Your reference in the RMC system [properties setObject:@"User Token for Push Message" forKey:@"OM.sys.TokenID"]; [properties setObject:@"AppAlias" forKey:@"OM.sys.AppID"]; [[Visilabs callAPI] customEvent:@"Campaign" withProperties:properties];
SwiftCode Block language swift var properties = [String:String]() properties["utm_campaign"] = "campaign_name" properties["utm_source"] = "related" properties["utm_medium"] = "apppush" properties["OM.exVisitorID "] = "KeyID or Email" //Your reference in the RMC system properties["OM.sys.TokenID"] = "User Token for Push Message" properties["OM.sys.AppID"] = "AppAlias" Visilabs.callAPI().customEvent("Campaign", withProperties: NSMutableDictionary(dictionary: p
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.
Swift
Code Block | ||
---|---|---|
| ||
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)
}
}
} |
Objective-C
Code Block | ||
---|---|---|
| ||
#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.
...
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 |
RMC Personalization (visilabs)
...
...
language | applescript |
---|---|
linenumbers | true |
Parent Topic: Push SDK
Code Block |
---|
- (void) application:(UIApplication *)application |
...
didRegisterForRemoteNotificationsWithDeviceToken:( |
...
NSData *) |
...
deviceToken { NSLog(@" |
...
didRegisterForRemoteNotificationsWithDeviceToken"); |
...
|
...
|
...
[ |
...
[EuroManager sharedManager:@" |
...
AppcentIOSTest1"] |
...
registerToken:deviceToken];
} |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"User Info Description: %@",userInfo.debugDescription);
[[EuroManager sharedManager:@"VisilabsIOSDemo"] handlePush:userInfo];
}