#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; // un esempio di puship_id potrebbe essere: "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)); } });
Si, questo è tutto!
Puoi ora connetterti al Puship Manager e inviare notifiche push ai tuoi device!
Per qualunque problema con la configurazione puoi scaricare l’esempio qui sotto
Per poter invece aggiungere tags, gestire la geolocalizzazione e tutto ciò che riguarda il resto delle api puship visita la documentazione comune per tutte le piattaforme:
Documentazione sulla libreria Common