Pergunta

I have a very special problem of synchronization with my application that i would like to share with you and get some ideas that hopefully will help me solve it.

I am developing an application that basically does 2 things :

1) Registers for push notifications in AppDelegate .

2) Opens a webView in ViewController and loads a URL. The form of the URL that is loaded is always like this : http://.www.thisIsMyUrl.com/UDID , where UDID is users unique identifier.

In the didRegisterForRemoteNotificationsWithDeviceToken: i am registering for a token and after i receive it , inside this function i make an http request to my server where i send the push token and the UDID.

So in both the didRegisterForRemoteNotificationsWithDeviceToken of the AppDelegate and in the ViewController i was retrieving the UDID and using it as i described.

Everything till last week worked perfectly. However now Apple decided to reject any application using the UDID. So the way to go for me is create a unique identifier using the CFUUID and save it to Key Chain.

The problem :

As you see i make use of the unique identifier both in AppDelegate's didRegisterForRemoteNotificationsWithDeviceToken function an inside the ViewController. However it must be created in only one of these controllers or else it will be different!!! (Remember that CFUUID string is created with UDID + dateNtime).

Where should i create it ??? The didRegisterForRemoteNotificationsWithDeviceToken is asynchronous so if i retrieve it there , the viewController will make the http request long before the unique identifier reaches there and it will use a null instead. The same case could probably happen with the ViewController. If i try to create it there , maybe the didRegisterForRemoteNotificationsWithDeviceToken function will get called faster and will try to register in my database a null unique identifier .

So where can i try to create the CFUUID string and be sure that all the controllers will get it on time?

EDIT


An idea that just came on the top of my head. What if i created the CFUUID inside the didFinishLaunchingWithOptions function of the AppDelegate ?? If i am not mistaken this part of code will run FIRST , before anything else. So there wont be any synchronization problem as i ll pass it safely everywhere i need it. Right?

Foi útil?

Solução

As you said, didFinishLaunchingWithOptions is the first method to be executed when the application is launched.

If you create the CFUUID at the beginning of this method, before registering to push notifications, it will have a value when you receive the device token from Apple (when didRegisterForRemoteNotificationsWithDeviceToken is called), and it will have a value by the time you open your webView.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top