0

I have registered for PDF document type so I can open mail attachments and PDF files viewed in Safari. The problem is that works fine if the application is closed. If the application is in the background. Safari/Mail switches to my App but my App didFinishLaunchingWithOptions function is not called which include the URL to the file. So I cannot access the file in that case.

Do I need to force the user to close the App before opening any document in Safari!

EDIT: Here is my plist changes

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>PDF Document</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.content</string>
            <string>public.item</string>
            <string>public.data</string>
        </array>
    </dict>
</array>

I was messing with the values but public.content and public.item and public.data just register my App to open any content not just the PDF. still I need to close my App first!

Mahmoud Fayez
  • 3,398
  • 2
  • 19
  • 36
  • I havent done this before but according to the documentation and according to a test I just did (dropbox) it seems to restart the app by itself when you hit the 'open in...' option. How did you register the app in the plist? can you list the values? – KDaker Feb 05 '13 at 00:08
  • I just edited the question. – Mahmoud Fayez Feb 05 '13 at 00:12
  • i think you need to add the format the `LSItemContentTypes`: `com.adobe.pdf` ... according to [this](http://stackoverflow.com/a/3042827/442328) answer. – KDaker Feb 05 '13 at 00:28
  • I tried this before and same behaviour. public.item is more generic it is like wild card instead of defining PDF files only. – Mahmoud Fayez Feb 05 '13 at 00:30
  • read the last comment in the answer i linked. Seems to fix your issue. – KDaker Feb 05 '13 at 00:30

1 Answers1

0

@KDaker has pointed it out in the comments but the bottom line is that you need to implement these two functions in your Application delegate.

- (BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url;

- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
Mahmoud Fayez
  • 3,398
  • 2
  • 19
  • 36