IOs

  1. Download the phonegap plugin for iOS from this link ( iOS 4.2 or above).
  2. Drag the folder PushNotification from the Finder and Drop it into the Plugins one in XCode, using “Create groups for any added folders” and flaging “Copy items if needed”.
  3. Add the following line to config.xml to enable the plugin::
  4. Modify AppDelegate.h adding the following line:
      #import "PushNotification.h"
  5. Modify AppDelegate.m adding the following code before the @end @end tag:
      /* ... */
      
      /* 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
  6. Add the following code into the methoddidFinishLaunchingWithOptions, before the return YES:
      [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;
      
  7. Add the PushipNotification.js script to the assets/www folder and include it to the index.html file.
  8. Add the following code to the OnDeviceReady method:
      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: