Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I give an answer to my own question. Finding out the solution took me a while and was quite frustrating. If you do an internet search you find some partial answers, but it still took me a while to work out the following solution and I do hope it adds some clarity.</p> <p>So first, the recommended behavior of your app appears to be the following (see <a href="http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW20" rel="noreferrer">Opening Supported File Types</a> in iOS Ref Lib):</p> <ul> <li>Do not implement <code>applicationDidFinishLaunching:</code> (see the note at <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions:" rel="noreferrer">UIApplicationDelegate</a>).</li> <li>Implement <code>application:didFinishLaunchingWithOptions:</code> and check the URL, return YES if you can open it, otherwise NO, but do not open it.</li> <li>Implement <code>application:handleOpenURL:</code> and open the URL, return YES if successful, otherwise NO.</li> </ul> <p>In iOS 4, passing an URL to an app results in one of the following two behaviors:</p> <ul> <li>If the app is launched then <code>application:didFinishLaunchingWithOptions:</code> is called and <code>application:handleOpenURL:</code> is called if and <code>application:didFinishLaunchingWithOptions:</code> returned YES.</li> <li>If the app is becoming active from suspended state then <code>application:didFinishLaunchingWithOptions:</code> is not called but <code>application:handleOpenURL:</code> is called.</li> </ul> <p>However, in iOS 3.2 it appears as if <code>application:handleOpenURL:</code> is never called! A hint that the behavior is different under iOS 3.2 can be found in <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW14" rel="noreferrer">Handling URL Requests</a>. There you find that <code>application:handleOpenURL:</code> is called if <code>application:didFinishLaunchingWithOptions:</code> is not implemented, but <code>applicationDidFinishLaunching:</code> is implemented. But <code>application:handleOpenURL:</code> is not called if <code>application:didFinishLaunchingWithOptions:</code> is implemented.</p> <p>Hence, one solution to make the code work under 3.2 and 4.0 is:</p> <ul> <li>Open the URL in <code>application:didFinishLaunchingWithOptions:</code>, but then return NO to prevent that <code>application:handleOpenURL:</code> is called.</li> <li>Open the URL in <code>application:handleOpenURL:</code>, in case you are under 4.0 and the app was in suspended state.</li> </ul> <p>I found this solution in another post, but I was confused, because it contradicted the recommendation in iOS Ref Lib documentation (namely that we should return YES in <code>application:didFinishLaunchingWithOptions:</code>). (At that point I did not realize that the documentation contradicts it self).</p> <p>I believe that the current iOS 4.0 behavior will be the future behavior I prefer the following solution:</p> <ul> <li>Do not implement <code>applicationDidFinishLaunching:</code>.</li> <li>Implement <code>application:didFinishLaunchingWithOptions:</code> and check the URL, return YES if you can open it, otherwise NO, but do not open it. If we are on 3.2, open the URL.</li> <li>Implement <code>application:handleOpenURL:</code> and open the URL, return YES if successful, otherwise NO.</li> </ul> <p>So in summary, I implement the iOS 4 behavior and added the following line to <code>application:didFinishLaunchingWithOptions:</code></p> <p><code> <PRE> if([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3.2"]) { [self application:application handleOpenURL:url]; } </PRE> </code></p> <p>which make the code work under 3.2.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload