IOS urban Airship. How to Handling notifications - iphone

I am pretty new to this. I implemented the Urban Airship push notification and its working properly. Now I need to implement how to handle a push notication. I would like to show a tab or when the user clicks on the notification.
Appreciate any help.
Here is the instruction from urban airship and I dont know how to implement UAPushNotificationDelegate.
Handling notifications
iOS handles push notifications received outside the application, but if a notification is received while the app is running, it is up to the application developer to handle it.
The sample UI includes an implementation of UAPushNotificationDelegate that handles alerts, sounds and badges, however if you wish to customize this behavior, you can provide your own implementation:
[UAPush shared].delegate = customPushDelegate;

You would listen for an app delegate method and handle the notification:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateActive )
{
//do your handling here
}
}
If you pass in custom json objects you would also parse it here

Related

iPhone Push Notifications

I have a iPhone app that uses Push Notifications. My understanding of how this works is I need the "Device Token" of each iPhone before I can send a notification.
Using the test iPhones I have, I can obtain the Device Token from the xcode interface and store them in a data table which the Push Notification PHP script uses to send the notifications.
How do I send the Push Notifications to iPhones that install the app of which I do not know the Device Token ID.
I think my question is; do I need the Device Tokens before I can sent a notification to a iPhone.
If I do require the Device Token, how do I obtain it from iPhones using my app.
You can't receive any Push Notification with the Simulator.
You don't directly send a notification. You said to Apple's servers that there is a notification for this Device Token. Then iPhones themselves will ask automatically to receive push notifications is some are available.
To answer to your question : Yes you do. Without the Device Token you can't register your notification to Apple's server. Then you have to implement this register the device to get the DeviceToken:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
Here is you should look up == Push Notification Programming Guide
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"Error in registration. Error: %#", err);
}
See the code from apple Local and Push Notification Programming Guide, first you have to call registerForRemoteNotificationTypes in your app, and then in two delegates, you can get dev token or not, this token is from APNS, so when you get it, you will send it to your service to store it. And you can't get a device token from simulator.
Your push notification service will have to use the device token to send notification to your app, so you will definitely need it. In additional, you will have to get SSL certificates from apple dev center, that requires an valid paid developer ID of iOS.
For more information, please check Push Notification Programming Guide, and it's a great help.
Furthermore, I tried this PHP library to test push notification service, and it's good, you can just find its unit test, and paste the device token there, and run it, you will get message from it.
sly/notification-pusher

Push Notification Object

My app receives push notifications and sometimes these notifications come with an object that has to be stored on core data.
What happens if one of these notifications with an object arrives to the application when it is not running?
How do I handle that?
thanks
If you have implemented method
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{}
It will be fired up for every notification during the sleep, when the app becomes active.

How to post push notifications in APNS and how to show the notifications in iPhone?

I have several doubts about APNS. Am trying myself to make clear on the APNS but still need some clarifications. I have to know how we are posting push notification in APN Server and how we push the notification to Apple APN Server? And also how am i receive the notification from Apple and show the notification to user? I know we are receive the Notifications from below delegate,
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
How we should show the notifications to the user, please suggest any sample codes? Please clarify my silly doubts. Thanks in advance. Please help me.
this tutorial is useful please see
http://mobiforge.com/developing/story/programming-apple-push-notification-services
when you receive push notificaion ,please NSLog userInfo
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NsLog("%#",userInfo);
}
push notificaion is come only one time , pop is open for about 10 second(Depend on notifcation type)... if you click then didReceiveRemoteNotification delegte is call , if you can't click any reason you see notificaion by go to setting->notification click...and check
if you want store total push notifaction use the database and store in your database

Push Notifications using Urban Airship correctly

I tried using Urban Airship for sending push notifications to the devices.
I register the device to push using:
Code:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
I created an app on Urban Airship, uploaded the certificate key and tried sending a broadcast with no success.
Only when I manually added the device token to Urban Airship, I successfully sent and got a broadcast.
My question is - can I use Urban Airship to send Push notifications without registering device tokens and how? If not, how do I register the device tokens automatically from the app (and not using the curl code)?
Is there any other push provider which doesn't require more than Apple's basic registerForRemoteNotificationTypes: method?
Thanks!
No, Urban Airhip cannot send push notifications if the device does not register on the network, think about that logic. registerForRemoteNotificationTypes: simply initiates the registration process and assumes you have done the rest of the leg work to make that magic happen.
You also need the rest of the delegates to properly register and receive Push Notifications on your device.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
In addition to these UIApplication delegates, you need to initiate the Airship classes by doing the following in your didFinishLaunchingWithOptions: delegate:
[Airship takeOff: kApplicationKey identifiedBy: kApplicationSecret];

What are the steps in implementing Apple Push Notification?

I am new to this topic and require some guidance in implementing Apple Push Notification in my application. I have created my appID and also configured Apple Push Notification for the same. I have downloaded the provisioning profile and installed the app on the iphone. I have also written the following code provided by Apple documentation
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
const void *devTokenBytes = [devToken bytes];
NSLog(#"devToken=%#",devTokenBytes);
//self.registered = YES;
//[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSLog(#"Error in registration. Error: %#", err);
}
I want to know what I have to write on the server side. When I run the code it says that the device is not registered. How can I register my application for the push notification.
Can anyone help me with this...
Any code will be very helpful...
Thanx in advance...
You need to tell your server about the device token returned by Apple when you register for notifications from the device, so that the server can present the same token and app id when it tells the apple server that there's a new notification. Have you done that? I believe the device token could change each time you register, so you'll need to keep track of that on your server (and tell the server each time).
You've shown the callbacks involved in device registration, but have you actually called the registration method itself?
You also got to listen to didReceiveRemoteNotification in case you want to know when notifications arrive also when the app is in foreground. You might also want to clear the badge number set on the app icon when the user has read the notification it was sent.