How can I use universal links when I call openURL inside my own app?

Ricardo

My app uses in different screens:

[[UIApplication sharedApplication] openURL:url];

in order to open URLs received from my web service. Sometimes, those URLs are unrelated to my project, so opening them going to Safari is OK. Others, those URLs belong to my own, like a product detail. Those ones could be opened by my app using universal links and going to the proper screen, but that's not happening.

Reading apple docs I saw this:

It’s important to understand that if your app uses openURL: to open a universal link to your website, the link does not open in your app. In this scenario, iOS recognizes that the call originates from your app and therefore should not be handled as a universal link by your app.

https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

That behaviour confuses me. How can I use openURL to try to process first that URL inside my app instead of going directly to Safari?

I found a fast/dirty workaround. Remove openURL and use this every time my app uses openURL:

NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
userActivity.webpageURL = url;
[[UIApplication sharedApplication].delegate application:[UIApplication sharedApplication] continueUserActivity:userActivity restorationHandler:nil];

Note that my appdelegate application:continueUserActivity:restorationHandler: will forward to openURL any URL that does not have a specific screen in my app, so, it is working perfectly fine, but I feel this is a terrible solution.

Oleksiy Ivanov

Your solution seems reasonable. Why is that terrible?

Probably you can implement more nicely looking solution, like stand-alone class LinkHandler. The class can identify if link can be handled by your App (than it will use App's handling). Otherwise class will pass this link to iOS handling with [UIApplication openURL:].

A lot of Apps doing this, imagine how Google+ or Facebook iOS Apps would handle links, that posted in these social networks.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I use "<<" with my own struct?

分類Dev

How can I pass form data AND my own variables via jQuery Ajax call?

分類Dev

How can I call a function inside a class?

分類Dev

How can I use my own diff tool with `add --patch` and the like?

分類Dev

universal links when app is in background

分類Dev

How can I run my own personalized bash shell in Java?

分類Dev

How can I pass my class into its own constructor?

分類Dev

How can I make my bot delete its own message?

分類Dev

How can I create my own spelling file for vim?

分類Dev

How should I handle the shebang when writing my own shell?

分類Dev

How can I use regex to construct an API call in my Jekyll plugin?

分類Dev

How can I call OnActivityResult inside Fragment and how it work?

分類Dev

Can I Create my own Emoji?

分類Dev

How can I force my desktop browser to never use mobile Wikipedia links (e.g., en.m.wikipedia.org)

分類Dev

How can I find a blocking call inside Tornado webserver?

分類Dev

How can I call a key that is wrapped in qoutes inside of an object in vuejs?

分類Dev

how can i call function inside another function.?

分類Dev

How can I call a bash function in bash script inside awk?

分類Dev

Can I use the default image editor available in my iOS app?

分類Dev

Can I build a progressive web app showing a website which is not my own?

分類Dev

If I have location services turned on then how can my app get killed when it enters background mode?

分類Dev

How can I make AutoLayout crash my app when it logs unsatisfiable constraints in debug console?

分類Dev

How can I stop my change notifier provider from rebuilding my parent material app when I am rendering my child material app?

分類Dev

How do i get an Object of ObservableList in which i can write my own methods?

分類Dev

How can I make a table inside my shiny box with RandomIcon()

分類Dev

How can I get a legend to appear on my plot using my own desired colours?

分類Dev

How can I be my own Certificate Authority (CA) and generate ssh keys for my client computers

分類Dev

Can I define my own custom HTML Elements for use with css and js?

分類Dev

How can I make my button call a rotation of GIFs?

Related 関連記事

  1. 1

    How do I use "<<" with my own struct?

  2. 2

    How can I pass form data AND my own variables via jQuery Ajax call?

  3. 3

    How can I call a function inside a class?

  4. 4

    How can I use my own diff tool with `add --patch` and the like?

  5. 5

    universal links when app is in background

  6. 6

    How can I run my own personalized bash shell in Java?

  7. 7

    How can I pass my class into its own constructor?

  8. 8

    How can I make my bot delete its own message?

  9. 9

    How can I create my own spelling file for vim?

  10. 10

    How should I handle the shebang when writing my own shell?

  11. 11

    How can I use regex to construct an API call in my Jekyll plugin?

  12. 12

    How can I call OnActivityResult inside Fragment and how it work?

  13. 13

    Can I Create my own Emoji?

  14. 14

    How can I force my desktop browser to never use mobile Wikipedia links (e.g., en.m.wikipedia.org)

  15. 15

    How can I find a blocking call inside Tornado webserver?

  16. 16

    How can I call a key that is wrapped in qoutes inside of an object in vuejs?

  17. 17

    how can i call function inside another function.?

  18. 18

    How can I call a bash function in bash script inside awk?

  19. 19

    Can I use the default image editor available in my iOS app?

  20. 20

    Can I build a progressive web app showing a website which is not my own?

  21. 21

    If I have location services turned on then how can my app get killed when it enters background mode?

  22. 22

    How can I make AutoLayout crash my app when it logs unsatisfiable constraints in debug console?

  23. 23

    How can I stop my change notifier provider from rebuilding my parent material app when I am rendering my child material app?

  24. 24

    How do i get an Object of ObservableList in which i can write my own methods?

  25. 25

    How can I make a table inside my shiny box with RandomIcon()

  26. 26

    How can I get a legend to appear on my plot using my own desired colours?

  27. 27

    How can I be my own Certificate Authority (CA) and generate ssh keys for my client computers

  28. 28

    Can I define my own custom HTML Elements for use with css and js?

  29. 29

    How can I make my button call a rotation of GIFs?

ホットタグ

アーカイブ