iOS About APNS Device Token.

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
Hi all,

To implement Apple Push Notification, I need register my Iphone Application to APNS in didFinishLaunchingWithOptions method and then get the Device Token in didRegisterForRemoteNotificationsWithDeviceToken.

When I run my application for first time, the didFinishLaunchingWithOptions will get called. But when I run my application for second time, the didFinishLaunchingWithOptions will not get called. So, it seems my application just register one time to APNS that is the first time I run the application. So, what I worry about is if the device token changed next time, it seems I cannot get the latest device token although I had run my application.

Anyone have any idea on this? or I am thinking something wrong?

Any idea and comments are welcome. Thanks a lot :)
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Be carefull what you say, you are saying your didFinishLaunching won't run the second time.
that statement is FALSE.
Since you didn't define if your app is hard killed on your "task-bar", or if it's being run again fully.
If it's still in your task bar, then there are other delegate methods. to listen for your app to return to it's active state in your applicationDelegate.
 

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
Be carefull what you say, you are saying your didFinishLaunching won't run the second time.
that statement is FALSE.
Since you didn't define if your app is hard killed on your "task-bar", or if it's being run again fully.
If it's still in your task bar, then there are other delegate methods. to listen for your app to return to it's active state in your applicationDelegate.
Hi,

Thanks for your reply. :)

In my case is like this, when I first time run my application, the didFinishLaunching will get called. Let's say in this first run, I stop at "Login page". Then I press Home button in my Iphone. Next time, when I run my application again, I will saw a page I last visited (in this case is Login Page). This mean my apps does not start over again from first loading page. So, the didFinishLaunching will not get called for the second time I run my application. But the applicationDidBecomeActive method will get called everytime.

So, what I think is is it suitable I register my application to APNS in applicationDidBecomeActive method? This is because a lot of code sample is register application APNS in didFinishLaunching method.

Hope anyone can give me some advices. Thanks a lot. :)
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
It's best pratice to only send it to the server in the didFinishLaunching, why would they need to send a new token if the app is still active?
Just curious since it's best practice to just do it in the DidFinishLaunching
 

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
It's best pratice to only send it to the server in the didFinishLaunching, why would they need to send a new token if the app is still active?
Just curious since it's best practice to just do it in the DidFinishLaunching
Thanks for your reply. :)

Let's say if my application still in "task bar" for a few weeks and I no delete it from "task bar". So, is it possible in this period the device token will change?

(In this period, when I tapped my application icon, my application will run without called didFinishLaunching method).

Am I thinking something wrong?
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
your device token doesn't change.. This is a special token needed for APNS, so that won't change at all.
If you register, you will generate it, and add it to your backend.
BUT, i don't know much bout the backend part..
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Everytime you start your app, you should register for remote notifications, via the registerForRemoteNotificationTypes: call. No tokens needed.
:( Then i'm majorly confused myself, will need to need to check my code later. Sorry for confusion in meanwhile.
Think i'm messing up 'registerForRemoteNotificationTypes' and 'didRegister..'
since, registering isn't the problem, when you get a callback of didRegister, then you have the devicetoken as NSData, and that's what I meant, or I'm just messing up OP's original question..
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
:( Then i'm majorly confused myself, will need to need to check my code later. Sorry for confusion in meanwhile.
Think i'm messing up 'registerForRemoteNotificationTypes' and 'didRegister..'
since, registering isn't the problem, when you get a callback of didRegister, then you have the devicetoken as NSData, and that's what I meant, or I'm just messing up OP's original question..
didRegisterForRemoteNotificationsWithDeviceToken: does pass in a device token, which you are expected to pass on to your server. Perhaps you are confusing the deviceToken with the UDID.
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
didRegisterForRemoteNotificationsWithDeviceToken: does pass in a device token, which you are expected to pass on to your server. Perhaps you are confusing the deviceToken with the UDID.
I know what you are saying, you are preaching to the wrong choir (this is an expression you guys use right?)

But it's to the OP's quote
Let's say if my application still in "task bar" for a few weeks and I no delete it from "task bar". So, is it possible in this period the device token will change?
He was thinking the device token, that's what i was trying to explain.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.