On this Page:
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:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
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:
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken"); [[EuroManager sharedManager:@"AppcentIOSTest1"] registerToken:deviceToken]; }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { EuroManager.sharedManager("AppcentIOSTest1").registerToken(deviceToken) }
In the 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, APPCENTIOSTEST1 value is a code value that is given by RMC for your application.
EuroManager instance is activated as shown below:
[[EuroManager sharedManager:@"AppcentIOSTest1" setUserKey: @"egemen@visilabs.com"]; [[EuroManager sharedManager:@"AppcentIOSTest1"] setUserEmail: @"egemen@visilabs.com"]; [[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize];
let euroInstance: EuroManager = EuroManager.sharedManager("AppcentIOSTest1") euroInstance.setUserEmail("egemen@visilabs.com") euroInstance.setUserEmail("egemen@visilabs.com") euroInstance("AppcentIOSTest1").synchronize()
If the additional parameters of the user are known, they can be added as shown below:
euroInstance.userEmail = @"uysalmo@gmail.com"; [euroInstance setTwitterId:@"com90"]; [euroInstance setFacebookId:@"com90"]; [euroInstance setUserLatitude:41.11 andLongitude:29.12]; [euroInstance setAppVersion:@"1.0"]; [euroInstance setUserKey:@"ozanUysalKey"];
In any step, if you add a new parameter and want to send it to the RMC server, you should call the "synchronize" method:
[[EuroManager sharedManager:@"AppcentIOSTest1"] synchronize];
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSLog(@"didReceiveRemoteNotification : %@",userInfo); [[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo]; }
If you are using iOS 8 or later version, the following method should be called:
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"didReceiveRemoteNotification:fetchCompletionHandler : %@",userInfo); [[EuroManager sharedManager:@"AppcentIOSTest1"] handlePush:userInfo completionHandler:completionHandler]; }
When an interactive push is sent, the information of which button is clicked by the user should be transmitted to RMC. For this application: HANDLEACTIONWITHIDENTIFIER:FORREMOTENOTIFICATION:COMPLETIONHANDLER: method in the APPDELEGATE is called as shown below:
- (void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler { NSLog(@"push clicked : %@ %@",userInfo,identifier); [[EuroManager sharedManager:@"AppcentIOSTest1"] handleInteractiveAction:identifier userInfo:userInfo]; if(completionHandler != nil) { completionHandler(UIBackgroundFetchResultNewData); } }
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 |
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken"); [[EuroManager sharedManager:@"AppcentIOSTest1"] registerToken:deviceToken]; }