Push Notification is one of best way to interact with app users. Every mobile developer knows the importance of push notification in mobile apps. Push Notification provides near real-time updation of informations such as news,score updates,messages etc., to users. iOS provides APNS (Apple Push Notification Service) to send push notification data to applications installed on Apple devices. There are many third party push notification services are available like Parse,Urban airship, Carnival,Push woof etc. The benefits of using third party Push Notification service are,
- – Reduce Your code.
- – Save Your time and effort.
- – Manage the notifications easily.
This section will explain some simple steps to be followed to send push notification to iOS platform via Urban airship dashboard. The steps are given below.
- 1. Registration and login
- 2. Create Your first app in Urban airship
- 3. Set up your xcode project.
- 4. Send your first Push Notification
Registration and login
You need to create an account in Urban Airship using an email id and password. There are many pricing plans available. Select a pricing plan or select a free starter account. Click here to view the available account plans. After the successful registration, click manage your apps from Urban Airship dashboard to get started.
Create Your first app in Urban Airship
After the registration is completed, add your first app. You need to specify the following details to create an app.
The name of your app.
Upload an app icon.
You must select whether your app is in development mode or production mode. When you are setting up development and production apps, you have to configure them for push services. See the APNS Setup documentation for detailed instructions.
Select Platform that will use Urban Airship
Select your platform here. The available platforms are iOS, Android, Windows, Blackberry etc.
After selecting the iOS app platform, save your app.
Set up your xcode project
You have created an app in previous section. Then you need to set up the xcode project. First, create an xcode project for push notification. Then you have to follow some steps to set up your project. The steps are explained below.
Download Urban airship SDK
Download the latest version of libUAirship from Urban Airship. Unzip the SDK and add the libUAirship static library and headers into your project. Click here to download the latest version of Urban Airship SDK.
In the project’s build settings set “Enable Modules” field to “Yes” and “Link Frameworks Automatically ” to “Yes”.
The SDK can be included using the Urban Airship static library(iOS 7+) and Urban Airship Embedded framework(iOS 8+). The static library and embedded framework have different setup procedures.
Including Urban Airship SDK using Embedded framework(iOS 8+)
Add Airshipkit.XcodeProj into your app project in xcode.
-Link against embedded framework
Add the Airshipkit.framework file to the Embedded binaries section in the general tab for your project to link against the embedded framework.
Including static library (iOS 7+)
– Search paths
Ensure that your project’s header search paths under build settings include the Airship directory.
– Linker Flags
Add –objC –lz –lsqlite3 linker flag to prevent “Selector Not Recognized” runtime exceptions and to include linkage to libz and libsqlite3. The linker flag –force_load<path to library>/ libUAirship<version.a> may be used in instances where using the –objC linker flag is undesirable.
– Link against the static library
In the libraries section in the Build Phases, add the libUAirship.a file to the link binary to link against the static library.
– Add the Urban Airship resource bundle
Add the UrbanAirshipResources.Bundle file to the Copy Bundle Resources section in the Build Phases tab for your target.
Enable Background Notification
You can enable Background notification by enabling Remote notifications of Background mode under the target’s capabilities section.
To manage your production and development application profiles, the Urban Airship SDK uses a .plist configuration file named AirshipConfig.plist. You can create two application within your Urban Airship account:one for development and one for production. Create an AirshipConfig.plist and set the following values in your .plist file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<string>Your Development App Key</string>
<string>Your Development App Secret</string>
<string>Your Production App Key</string>
<string>Your Production App Secret</string>
- Import the required header files
Import the AirshipKit header files to your application delegate.
Import AirshipKit (Swift)
You must import the individual headers if your application uses the static library.
Starting Urban Airship Services
Inside your application delegate’s application:didFinishLaunchingWithOptions:method,initialize a shared Uairship instance by calling Uairship takeoff.This will bootstrap the Airship SDK.
Retrieving your channel ID
The channel ID is a unique identifier used to target pushes to a specific devices using the Urban Airship API.You can always get the channel ID using the following code.
NSString *Channelid=[Uairship push].channelID;
NSLog(@”My channelID:%@”, Channelid);
print(”My channelID:%@”, Channelid)
ChannelID initially comes back as NULL on your apps first run.It will be created and persisted during registration.
Enabling User Notifications
By default User notifications are disabled.To enable notification write the following code. Set the user notification types on [Uairship push]. Sounds, alerts and badges are the default types. The library will register to receive notification after the user push notifications are enabled.
[UAirship push].userNotifictionTypes=(UIUserNotificationtypeAlert| UIUserNotificationtypeBadge|UIUserNotificationtypeSound)
After all this steps your project’s AppDelegate.m file looks like below
@interface AppDelegate ()
//Set the icon badge to zero
Send your first push Notification
You need to add a list of test devices in Urban airship console before sending your first notification. To setting up test devices, select Audience. You can see a text box for entering list of device identifiers. You can enter up to 100 device identifier here. After entering the device identifiers save the list.
To send your first push notification,navigate to Messages Overview ,located under the Messages tab,and click + Messages. You can see a Message box here and type your notification message here. Before sending the notification you have to select the audience and delivery options. The audience are,
segments are groups of audience that you can create using combinations of location,tags and lists.
Test devices are predefined devices created by an account administrator.
Select an audience from the list. Then navigate to the delivery section and you can see two options here.
Deliver the message immediately.
Deliver the messages according to the scheduled time
If all has been set up correctly,click Confirm and Send Now.
You have sent your first push notification!!!