#import "PushNotification.h"
/* ... */ /* START BLOCK */ #pragma PushNotification delegation - (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication*)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; [pushHandler didFailToRegisterForRemoteNotificationsWithError:error]; } - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; // Get application state for iOS4.x+ devices, otherwise assume active UIApplicationState appState = UIApplicationStateActive; if ([application respondsToSelector:@selector(applicationState)]) { appState = application.applicationState; } [mutableUserInfo setValue:@"0" forKey:@"applicationLaunchNotification"]; if (appState == UIApplicationStateActive) { [mutableUserInfo setValue:@"1" forKey:@"applicationStateActive"]; [pushHandler didReceiveRemoteNotification:mutableUserInfo]; } else { [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"]; [pushHandler.pendingNotifications addObject:mutableUserInfo]; } } /* STOP BLOCK */ @end
[self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; /* START BLOCK */ // PushNotification - Handle launch from a push notification NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if(userInfo) { PushNotification *pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; [mutableUserInfo setValue:@"1" forKey:@"applicationLaunchNotification"]; [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; [pushHandler.pendingNotifications addObject:mutableUserInfo]; } /* STOP BLOCK */ return YES;
Puship.PushipAppId = puship_id; // an example of puship_id might be: "h1mCVGaP9dtGnwG" Puship.APNS.Register( { successCallback: function (pushipresult){ navigator.notification.alert("device registered with DeviceId:" + pushipresult.DeviceId); }, failCallback: function (pushipresult){ navigator.notification.alert("error during registration: "+ JSON.stringify(pushipresult)); } });
It’s now possible to connect to the Puship Manager and start sending push notification to your devices!
Download a complete example using the link below to better understand the whole process
Adding tags, geolocations management and all the other api are described in the guide common to all the platform that can be consulted at the following link: