THIS CONTENT DOWNLOAD SHORTLY

Objective

The main objective of this tutorial is to learn how to Integrate Pushwoosh SDK in iOS Application.

 

 

Step 1 Introduction

What is Push Notifications?

  • Push notification is a message alert delivered by a centralized server to an endpoint device.
  • Push Notifications allows your application to notify users about some things. i.e message, score, results, events etc.

What is Pushwoosh?

  • Pushwoosh is third party service for push notifications to registered devices with applications.
  • It offers a variety of accounts and plans as per the requirement of the user.
  • PushWoosh API is used to access and integrate the functionality of PushWoosh with other applications.

This blog post will help you integrate Push Notification Service in your iOS Applications & show how to send notifications using Pushwoosh Third party service as well.

 

Step 2 Create Demo Project

First of all, Create one sample Xcode project. If you don't know how to create Xcode project, I recommend you to visit:

Here are some interesting iOS Blog Posts, that can help you learn iOS application development.

 

Step 3 Pushwoosh Account Creation

Create a Pushwoosh account to access their services.

pushwoosh

Now, click on Start Now button and fill all the necessary information to Sign Up. If you already have a Pushwoosh account, login to your account.

Once you logged in, you will get the following screen:

pushwoosh_applications

 

Step 4 Pushwoosh Application Creation

Now, click on Add New button, it will open the following screen.

pushwoosh_general_settings

Now, give appropriate Application Title and click on Save Application button. Upload Icon if you wish. it’s optional. Choose iOS SDK in SDK Settings, I've selected Pushwoosh.

Once you save your application, you will get the following screen:

pushwoosh_configuration_settings

Application code highlighted in above screen will be used in our application for Pushwoosh integration later. Click Configure button as displayed in above picture.

 

Step 5 Configure iOS Application

You must have got the following screen now.

pushwoosh_ios_settings

Select Manual tab and browse your certificate file (.cer) and Push certificate (.p12). Enter your private key password for .p12 file which you already set while creating .p12 file.

If you have no any idea about how to create this .cer and .p12 file then please refer to:

Now, click on Save button.

If you configured properly then next window will replace Configure button with Edit button as shown below:

pushwoosh_edit_platform_configuration

 

Step 6 Integrate Pushwoosh.framework

Now, Download Pushwoosh.framework & follow the steps given below:

  1. Unzip downloaded Pushwoosh.framework
  2. Go to Framework folder
  3. Copy Pushwoosh.framework to your directory folder as following:

    pushwoosh_framework
     
  4. Now, add this Pushwoosh.framework in your project by following the steps given below:
    1. Open your Xcode project
    2. Right-click on project folder, Select Add file to PushwooshDemo
    3. Choose your framework location & click Add and project navigation will be something like this:

      pushwoosh_appdelegate
 

Step 7 Add Other Framework

Now, go to Build Phases and Link Binary with Libraries.

Add following frameworks:

  • libstdc++
  • libz

Your screen will look like:

pushwoosh_buildphases

 

Step 8 Info.plist File Setting

Now, add one key-value pair for Pushwoosh Application configuration in your Info.plist file as following.

pushwoosh_info_plist_pushwoosh_appid

Here, the key is Pushwoosh_APPID with type String and Its value is 634AF-C9A48 which is generated in Step 3 (Application Code).

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    //-----------PUSHWOOSH PART-----------
    // set custom delegate for push handling, in our case - view controller
    PushNotificationManager * pushManager = [PushNotificationManager pushManager];
    pushManager.delegate = self;
    
    // handling push on app start
    [[PushNotificationManager pushManager] handlePushReceived:launchOptions];
    
    // make sure we count app open in Pushwoosh stats
    [[PushNotificationManager pushManager] sendAppOpen];
    
    // register for push notifications!
    [[PushNotificationManager pushManager] registerForPushNotifications];
    
    return YES;
}

 

Step 9 AppDelegate.m File

Now, configure Pushwoosh service in your iOS project through AppDelegate.m such as following.

#import "AppDelegate.h"
#import <Pushwoosh/PushNotificationManager.h>

@import CoreLocation;
@import SystemConfiguration;
@import AVFoundation;
@import ImageIO;

@interface AppDelegate () <PushNotificationDelegate>

@end

@implementation AppDelegate

Now, go to didFinishLaunchingWithOptions() method of AppDelegate.m file & replace this method with the code given below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    //-----------PUSHWOOSH PART-----------
    // set custom delegate for push handling, in our case - view controller
    PushNotificationManager * pushManager = [PushNotificationManager pushManager];
    pushManager.delegate = self;
    
    // handling push on app start
    [[PushNotificationManager pushManager] handlePushReceived:launchOptions];
    
    // make sure we count app open in Pushwoosh stats
    [[PushNotificationManager pushManager] sendAppOpen];
    
    // register for push notifications!
    [[PushNotificationManager pushManager] registerForPushNotifications];
    
    return YES;
}
 

Step 10 Pushwoosh Delegate Methods

There are few methods provided by Pushwoosh in Pushwoosh.framework which helps you perform actions or to handle push notification which is sent by Pushwoosh Service.

Here, we implement PushNotificationDelegate methods in AppDelegate.m file such as follows.

AppDelegate.m

// system push notification registration success callback, delegate to pushManager
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [[PushNotificationManager pushManager] handlePushRegistration:deviceToken];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Device Token" message:[NSString stringWithFormat:@"didRegisterForRemoteNotificationsWithDeviceToken : %@", deviceToken] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:alertAction];
        
        [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
    });
}

// system push notification registration error callback, delegate to pushManager
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    [[PushNotificationManager pushManager] handlePushRegistrationFailure:error];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Fail Register" message:[NSString stringWithFormat:@"didFailToRegisterForRemoteNotificationsWithError : %@", error.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:alertAction];
        
        [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
    });
}

// system push notifications callback, delegate to pushManager
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [[PushNotificationManager pushManager] handlePushReceived:userInfo];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Receive Notification" message:[NSString stringWithFormat:@"didReceiveRemoteNotification : %@", userInfo] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:alertAction];
        
        [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
    });
}

- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification
{
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Push Notification" message:[NSString stringWithFormat:@"onPushAccepted : %@", pushNotification] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:alertAction];
        
        [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
    });
}

Note

  • Push Notifications does not work in Simulator. So, You must test this code/demo in iOS Device only. You can test Push Notifications in any of the iOS Devices(iPhone/iPad).
 

Step 11 Final Build & Run

Generate proper development/distribution certificate for your app. If you have no idea about it then refer to:

Now, Select your device, build (cmd + b) and run (cmd + r). When application is run for the first time, it will ask for the permission for receiving push notification and you must Allow it:

pushwoosh_notification_permission

Once you agree, As soon as you run an application, every time Push service will get your Device Token which is not visible to users.

pushwoosh_receive_notification

Step 12 Send Push from Pushwoosh

Now, go to Pushwoosh Dashboard, open your application. Follow the steps shown below to push notifications:

  1. Go to your PooshWhoosh application.

    pushwoosh_push_message
    Enter your push message and select all other option as per your requirements.
     
  2. Make your Platforms settings as per your requirements.

    pushwoosh_platform_settings
    It will display output as above.
     
  3. Click on Woosh! button to send the Push.

    pushwoosh_summary
 

Step 13 Pushwoosh Notification Output

Now, you will get notification in the following manner:

  1. When Application is running, you will get a notification such as follows. (We handled it in our AppDelegate.m )

    pushwoosh_receive_notification
     
  2. You will get notification such as following if Application is not currently running

    pushwoosh_notification_receive
     
  3. When you tap the notification, it will directly open the application and show alert such as following.(Handled in AppDelegate.m file)

    pushwoosh_push_notification

    Each Output Screen will display UIAlertController message and its alert message starts with methods of PushNotificationDelegate delegate which is used to handle push notification sent by Pushwoosh.

I hope you will find this blog post helpful while working with Push Notification in iOS. Let me know in a comment if you have any questions regarding Push Notification in iOS Application. Please put a comment here and we will get back to you ASAP.

Got an Idea of iPhone App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best iPhone App Development Company in India.

I am iOS Application Developer & I personally believed that When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers cannot speak English.

face mask Belial The Demon Headgear Pocket Staff Magic