How to Send Device Token in APNS - iphone

I Have implemented following code but not getting the Device Token?
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(#"deviceToken: %#", deviceToken);
}

If you don't already, you should have a call to registerForRemoteNotificationTypes in your didFinishLaunchingWithOptions. Something along the lines of:
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
You should also have a didFailToRegisterForRemoteNotificationsWithError method that gets called if registration fails. The NSerror it gets should tell you more about why it might be failing.

Are you trying inside of the simulator ?
Push notification and related appdelagate events doesn't work on simulator.
If you are using the device,
Make sure that bundle identifier of your application must be same with your push ssl bundle identitifier which you defined during creating AppID on iphone privisioning protal.

For registering your device with APNs, you will first have to call
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
this is usually written in your AppDelegate (in didFinishLaunching ).
Then make sure you have implemented the
didRegisterForRemoteNotificationsWithDeviceToken
which provides you with the device token and
didFailToRegisterForRemoteNotificationsWithError
which gives you the error your code might have encountered.

Related

can you answer a push notification with your voice?

can you answer a push notification with your voice? So when you iPhone is locked and you get a push notification, can you react to it with you voice?
You're not registered for audio push notifications in your app. Just register for it like this in your App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever you have already in your app delegate...
// Let device know you're going to be sending one of these types of notifications.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
The 5 types are:
UIRemoteNotificationTypeBadge
UIRemoteNotificationTypeSound
UIRemoteNotificationTypeAlert
UIRemoteNotificationTypeNone
UIRemoteNotificationTypeNewsstandContentAvailability
Here's the documentation: Registering for Remote Notifications
also refere this documents
Hope that helps!
You can not play voice in push notification.Push notification Payload not contain your voice.
Users see notifications in the following ways:
Displaying an alert or banner
Badging the app’s icon
Playing a sound.
According to apple push notification document

Push Notification Delegates not getting called

I am implementing push notification for a client. I have followed all the steps of push notifications setup on device (including certificate generation and everything).
I have used following links as reference:
Apple Push Notification Services Tutorial
Programming Apple Push Notification Services
I call this function in app delegates didFinishLaunchingWithOptions
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
After setup, i run the app i get the Blue Push notification warning dialogue but after I press Ok the delegates are not called.
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
None of these delegates are called ever. I am stuck here as i cannot proceed further as none of the delegates is called.
If any of you has faced a similar issue i would be very very thankful if you can help me out here.
I have seen this before, you need to just add [application registerForRemoteNotifications]; to your code, where application is the instance of UIApplication inside the didFinishLaunchingWithOptions method of the app delegate. Make sure you add this once you have set up your UINotificationType, and UIUserNotificationSettings

Push notification badges not appearing?

I'm using Urban Airship to send push notifications to my app
eg:
{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}
The alert will display perfectly, however the app icon is never badged regardless of what I set "badge":# to...
Is my payload incorrect or is there extra code I'm supposed to add to my app to handle badges as well as alerts? Thanks!
EDIT:
I'm registering for push notifications like this:
// Register for notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
I was running with a similar problem. After a few minutes of checking around. I notice that there was a problem with my server side code. I found out that badge value has to be implicitly set as an integer to get the desired result. Hope that helps anyone reading this.
set the following code in the appdelegate .m file..
-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
//[self addMessageFromRemoteNotification:userInfo];
NSString* alertValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
NSLog(#"my message-- %#",alertValue);
int badgeValue= [alertValue intValue];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}
In iOS 5 there is a Settings -> Notifications. Double check that the Badge App Icon is turned on.
I assume that the app is not in the foreground when you were testing? It if is in the foreground then you have to handle badging manually.

Problem With PushNotification if you select No at the first time

As i said in the title of this thread, I have a problem with Push notification of my application.
There is 2 cases :
When the app asks you if you want push notification and you push OK, it's working great.
This function :
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
is called when registerForRemoteNotificationTypes is called :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Add registration for remote notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
...
}
But when you select NO at the beginning, and then you change your settings to accept push notification, nothing append and this function didRegisterForRemoteNotificationsWithDeviceToken is never called.
Please help me, i'm getting crazy!
I see you register for remote notifications in:
- (void)applicationDidFinishLaunching:(UIApplication *)application
If your application is running on a iOS device with support for multitasking that might not be the right place.
The above method is called when you initially launch your app from cold. This is when you are prompted to accept or decline Push Notifications - and in your case decline.
When you later exit the application to change the settings in the device wide control panel the application is not quit - it is merely resigning as the foreground application. When you have enabled Push Notifications in the control panel and return to your application - the application is not launched again but moves from being backgrounded to the foreground.
Your application delegate will at this point receive an:
- (void) applicationDidBecomeActive:(UIApplication *)application
try registering for Push Notifications there instead using:
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
You could also prevent backgrounding by setting the “Application does not run in background” property in the application’s Info.plist file (UIApplicationExitsOnSuspend).

Can an iPhone application relaunch itself when terminated?

I have two requirements for my latest project:
When the app launches for the first time it should display the device native dialer and then check for callDidConnected in background.
once the callDidConnected is true app should launch itself.
Here I tried the following logic:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//i am dialing to a IVR from the native dialer
if (/* A check to validate wether to call or not */)
{
NSLog(#"Dialing");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:"]];
// A loop check wether the call get connected
while (!callDidConnected){
callDidConnected = // doing a check with server
}
// if call get connected then launching my application
if (callDidConnected){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"MyApp:"]];
}
}
else
{
// normal app
}
}
- (void) applicationWillTerminate:(UIApplication *)application
{
}
I registered the app with URL MyApp.
I tested this code on simulator(on SDK 3.0/3.2) with opening another app(tried http instead of tel protocol). The check executes in background while other native app(safari) run in foreground.
"So this look a little odd" the Apple guys says.
Can any one help me to find whether I can use this code in my work, and will it be acceptable by Apple store.
No this is not possible or acceptable.
Think about it: the iPhone would not be able to do anything other than run this app, since it would instantly launch again when you quit it... Sounds like malware to me. Not something I'd ever want on my iPhone, and I'm happy that Apple restrict this kind of thing.