How to open URL schemes from Safari in iOS9? - ios

I was able to open apps from safari this way:
window.location = 'myapp://do/xx';
or open facebook app:
window.location = 'fb://';
But this stopped working in iOS9.
How can I open apps using URL schemes in safari?

IOS 9 URL Shchemes Update :
iOS 9 introduces LSApplicationQueriesSchemes to allow apps to query if other apps are installed.
1- If a url scheme is declared and calling canOpenURL(scheme)
YES if a installed app supports that URL scheme
NO if no app supporting that url
syslog will show canOpenURL: failed for URL: "urlScheme://" - error: null
2- If a url scheme is not declared and calling canOpenURL(scheme)
always return NO
syslog will show canOpenURL: failed for URL: "urlScheme://" - error: null
In iOS 9, the developer must add these info.plist
LSApplicationQueriesSchemes
<array>
<string>urlscheme</string>
<string>urlscheme2</string>
<string>urlscheme3</string>
<string>urlscheme4</string>
</array>
50 max. unqiue URL scheme can be declared!

With iOS9, Apple is changing a few things concerning URL schemes. Here is an article about those changes.
Basically, you now have to register all URL schemes that are supported by your app in your .plist file.

With the general release of ios9 setting window.location to a custom url does launch the app, but only after the user hits open in a popup. I filed a bug with apple about this, and they responded saying that it was intended behavior for launching an app from safari. They said they would look into the issue where if you hit cancel it fails out on future attempts.

Just assign a desired address to the href property, instead of trying to replace the whole window.location object:
window.location.href = 'myapp://do/xx';
It works for me on iOS 9.0.2, but now safari shows a confirmation dialog to ensure а user really wants open your link in the app.

this is how I have revised my Facebook/Google Login integration to get it work on latest update. which now user Safari web view.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>com.googleusercontent.apps.39373238582-opjuqokmar2i5t3sdk2vs5sifer4moen</string>
<string>com-google-gidconsent-google</string>
<string>com-google-gidconsent-youtube</string>
<string>com-google-gidconsent</string>
<string>com.google.gppconsent.2.4.1</string>
<string>com.google.gppconsent.2.4.0</string>
<string>googlechrome</string>
<string>googlechrome-x-callback</string>
</array>

Related

How to make deep links work in flutter when opened with gmail?

I am trying to implement deep linking in my flutter app. I am using the uni_links flutter package.
I am sending the deeplink for my application to the user's email account. However, in gmail, you need the http protocol in the href value, Otherwise gmail will not consider that as a valid link. Hence I am forced to use the following link in the email :
Click here
as opposed to a link like,
Click here
Now with https://myexample.flutter.dev, when I open the link from gmail, it doesn't open my app.
But, if I change my CFBundleURLSchemes key to myexample and CFBundleURLName to flutter.dev, when I type in myexample://flutter.dev in my browser, it opens my app. However, like I mentioned before, this is not recognized as a valid link in gmail.
What is the issue here? How do I resolve this?
Here's my ios/Runner/Info.plist :
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>myexample.flutter.dev</string>
<key>CFBundleURLSchemes</key>
<array>
<string>https</string>
</array>
</dict>
</array>
The first one is custom link you can do it by yourself
Click here
The second one is universal link
You need to provide file on the backend side to make it work.
Universal Links only work with https scheme and require a specified host, entitlements and a hosted file - apple-app-site-association.
Click here
UniversalLinksDocumentation
PS. I think right now as the end of the 2020 the best way to handle deeplinks is by Firebase Dynamic Links. Maybe future people will consider it it should be much more easier

Custom URL works in simulator but not on a device

I went through and followed this tutorial to use Custom URL. Everything works as expected on Simulator, so when I use safari and hit myApp:// a dialog pops up asking if I wish to open the app. SO far so good. However, when I installed the app on a device and hit the same thing in safari I get an error saying Cannot open page. Safari cannot open the page because the address is invalid. I tried this enough times, so it's definitely not a typing error. Any help is greatly appretiated.
.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.xyz.myApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>iOSMyApp</string>
</array>
</dict>
</array>
I copied my bundle identifier for CFBundleURLName.
ANSWER: So just before I was about to bang my head on the desk what I found that it's working when I open a new tab in Safari and then hit the app URL. And I have no idea why this happens. Also if you cancel it and then hit the app URL in the same tab again, it will give you an error I mentioned in the question. So the trick is to hit the app URL in a fresh tab everytime.
This setup is working for me. One thing I have to do is close the current tab of safari and open new one and type
iOSMyApp://

Allow opening my app from a link in a third-party app

I'm currently using a custom URL scheme to allow users to access my app (say, FoobarApp) from custom links (foobar://resource/42).
I set up the scheme like so :
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.acme.foobarapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>foobar</string>
</array>
</dict>
</array>
This works well when the users click the link in Safari.
Now I'd like them to be able to click said links in third-party apps (in my case Trello), to open my app.
This does not work, as the system (since iOS 9 if I'm not mistaken) now requires that apps whitelist URL scheme they want to query (with the LSApplicationQueriesSchemes in Info.plist).
(This is the message I get in the logs when I click the link in the third-party app:
iPad Trello(UIKit)[2368] : -canOpenURL: failed for URL: "foobar://resource/42" - error: "This app is not allowed to query for scheme foobar"
)
It's not reasonable to expect the third-party app to add my (enterprise) app's scheme to their LSApplicationQueriesSchemes list. Is their any option to "bypass" this protection? A kind of way to tell the system "It's fine, Trello can open my app"?
Summary
Custom app links foobar:// work in Safari
They don't work in third-party app (nothing happens, see log a few lines up)
How can I whitelist third-party apps so they can open my app?
an app has to tell ios it wants to query a url scheme. It has to declare this in its info plist at compile time!
There is no way around this on a apple allowed iPhone.
Sure when you jailbreak a phone, all can be done but... thats not a valid assumption either ;)
a workaround may be to link to a Website via HTTP and have the user open the app from there.

Swift Open Facebook Profile by FacebookUID

I'm trying to open a user's Facebook profile in Swift using their Facebook UID. In the Simulator, it works and opens up the web version of the profile and works fine, however on my actual device, it opens up the Facebook native app and gives me a "Page not Found" error.
guard let facebookUID = self.user?.facebookUID else {
return
}
print(facebookUID)
let fbURLWeb: NSURL = NSURL(string: "https://www.facebook.com/\(facebookUID)")!
let fbURLID: NSURL = NSURL(string: "fb://profile/\(facebookUID)")!
if(UIApplication.sharedApplication().canOpenURL(fbURLID)){
// FB installed
UIApplication.sharedApplication().openURL(fbURLID)
} else {
// FB is not installed, open in safari
UIApplication.sharedApplication().openURL(fbURLWeb)
}
What am I doing wrong?
Thanks in advance!
EDIT
I've noticed that if a user deletes or doesn't have the Facebook app installed on their phone, it will open up the profile correctly through Safari, which is why it worked on the simulator, but didn't on my device. However, I've also noticed I can get it to work in the Facebook app if I try a public profile like fb://profile/4 (which is Mark Zuckerburg's profile).
Hi based on documentation Facebook ID is the App-scoped User ID so you can use like
fb://profile?app_scoped_user_id=%#
But also check bug report on https://developers.facebook.com/bugs/332195860270199 opening the Facebook profile with
fb://profile?app_scoped_user_id=%#
is not supported.
So you will have to open the Facebook profile within Safari or you can use in app webview to open user profile.
I have check with some facebook id 10000****889,10000***041 etc. all have open profile in facebook app.Yes some have same error.Page bot found.
May be there is Privacy setting->Do you want search engine outside link to your profile->No. restrict search.
To get ids of user from facebook Trick :
1)Right click on the person or page's profile photo, select properties and the ID will be included in the page
2)In mobile browswe if you open photo there is id E.g.
" fbid = *** & pid = 1000....89 " so 1000....89 will be your user id
Here is another solution that works for iOS 10 & Swift 3.
First of all, you should add LSApplicationQueriesSchemes key to Info.plist file. If you do not add this key, canOpenURL will always return false. Than you need to add what scheme(s) you want to check. Use fb for facebook.
It should looks like this:
The rest is Swift:
if UIApplication.shared.canOpenURL(URL(string: "fb://profile/PROFILE_ID")!) {
UIApplication.shared.open(URL(string: "fb://profile/PROFILE_ID")!, options: [:])
} else {
UIApplication.shared.open(URL(string: "https://facebook.com/PROFILE_ID")!, options: [:])
}
Note: Replace PROFILE_ID with your target.
Thanks to vien vu.
From iOS 9 < above, You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist. So add this code to your plist file:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>comgooglemaps</string>
</array>
I able to use this URL scheme fb://profile?id={userid/username/pageid} to open a facebook user's profile / page as of 30 Aug 2020.
eg: fb://profile?id=4 OR fb://profile?id=zuck
Warning: Please use at your own risk as this is not documented in Facebook developers documentation. This URL scheme may be removed by Facebook app in the future without any warning and indication.
Swift 2.3
func goFacebook() {
let profileID = "" //Here put profile id Example:'62260589592'
let facebookURL = NSURL(string: "fb://profile/\(profileID)")!
if UIApplication.sharedApplication().canOpenURL(facebookURL) {
UIApplication.sharedApplication().openURL(facebookURL)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/PageName")!)
}
}
Note: If you can't find the facebook profile id can you use the follow site to do it (https://findmyfbid.com/)
Set in the info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
</array>

Apps Link not working in facebook and safari

I try to implement App Link in my IOS project. I've setup URL Schemes, and tested by typing testApps:// into mobile safari. Open apps dialog is prompt.
Im also setup a html file, access by public domain, www.testSite.com/testApps.html and include basic meta tag recommend by most Apps Link tutorial website. The file is shown as below:
<html>
<head>
<meta property="al:ios:url" content="testApps://default" />
<meta property="al:ios:app_name" content="testApps" />
</head>
</html>
However, safari do not prompt to open Apps when i key in the URL.
I also setup facebook apps setting, FB_test_Apps, set URL Scheme Suffix to be testApps, turn on Single sign on and Deep Linking.
I share www.testSite.com/testApps.html in facebook, and also from apps which register under facebook apps FB_test_Apps (which it will show as "Via FB_test_Apps" under the post).
When i click on this two post, Facebook will load it in facebook's webview. However it do not prompt to open my apps as well.
Is there anything i've missed out?
Update
I found out this issue only happen in IOS9. iOS 8 able to work well.
Regard
Steven
Yes iOS 9 has made some changes. You need to whitelist the url schemes you're using in your project.
Just add LSApplicationQueriesSchemes of type array in your info-plist and mention the urls you need to open in your project under it.
I guess too late to the party.
As mentioned above by Bhavuk, you have to white list the fb app for iOS9 and up.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
</array>
Referring from here.
iOS 9 not opening Instagram app with URL SCHEME

Resources