Universal linking with website by using swift - ios

I using Universal-linking in my application, For that, I make the following apple-app-site-association file, like with the following code.
I place this file into server please find here:- http://dev.2ULaundry.com/apple-app-site-association
I add Domain URL into under associated domain into Capabilities of project file also.
But my Universal linking is not working anyone please help to me.
"applinks": {
"apps": [],
"details": [
{
"appID": "D929J2.com.apple.wwdc",
"paths": [ "/scheduled-pickups/","/new-schedule/", "dashboard-1", "/refer-a-friend/", "/price-list/", "/give-a-gift/", "/locations", "2u-rewards/", "payments/"]
}
]
}
}
And add the following code into appdelegate file also for hadling.
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool
{
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
let userurl = url.absoluteString
if userurl.contains("/scheduled-pickups/")
{
let innerPage = UIStoryboard.loadPickupController()
innerPage.selectedfrom = SelectedFromVc.Deeplinking.rawValue
let nav = UINavigationController.init(rootViewController: innerPage)
nav.isNavigationBarHidden = true
self.window?.rootViewController = nav
}
}

You should check is your domain valid for using universal links. You could do it here: https://branch.io/resources/aasa-validator/.
I've checked your domain http://dev.2ulaundry.com there and there are some issues with your domain. Fix them and it should be fine.

Before the implementation, you have to verify your website domain with this AASA validator https://branch.io/resources/aasa-validator/. It has few warnings so please run the validator and fix the issue.
As per you shared, the domain starts with "http" but
Universal link only serves "https"
and also it would be good if you are placing the AASA file in the below path
https://dev.2ulaundry.com/.well-known/apple-app-site-association
Since I spent lot of times on Universal link & App links, my
recommendation is to use Firebase dynamic link for free or
Branch.io before wasting your time.Universal link will create lot of issues
like you can't check the app availability(app installed or not) and
you can't passing the parameter via Apple/Play store.

Related

run iOS app from web (angular)

I'm developing an iOS app
i have a payment page designed by angular
user click on a payment button in ios app and i run a url page with few paramaters :
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.testt.com/price/personId/packageName")!)
price is money user has entered in textfield and package-name id the schema name i should send it to web page that runs my app (return to app with running that string) i have declared in info.plist
then after been successful or unsuccessful payment. it should return to app by clicking on “return to app” button on web site.
actually angular runs the packageName i have sent with url like this way : http://packageName://
i tried to implement this by universal link like this way : packageName:// but wont open this link because of special chars in url.i used encoding method to encode chars but not successful because url removes the chars :// then i tried app site association method which i faced cannot parse app site association file
so i have few question for you :
1_is there any trick to run url with special chars ??
2_what would you do if you were me ??
3_i tried apple-app-site-association too but can not parse error which i have a question about this method how could this file opens my app? this way : applink:http://msite.com ?? because it contains spacial chars in it again
excuse my awful English at the end
talk to me before voting down
update :
var encodedChars="openMyApp" //schema name
encodedChars=encodedChars.addingPercentEncoding(withAllowedCharacters:CharacterSet.alphanumerics)!
let url="http://test.com/#/payment/\(id)/\(price!)/\(encodedChars)"
UIApplication.shared.openURL(NSURL(string: url)! as URL)
angular code :
if (this.accounting.packageName === 'openMyApp') {
this.url = this.accounting.packageName + '://';
} else {
this.url = 'http://' + this.accounting.packageName;
}
<a class="btn btn-default" title="" href="{{url}}"></a>
I have implemented custom url scheme for my app. If i write some thing like this
myappName://
in safari and press enter, my app is opened.
My angular + backend developer is using this line of code to open my app using custom url scheme. he is sending parameters along the scheme which i can read
this.document.location.href = 'myappname://appname.com/login?name='+id+'&id='+token;
Follow these 2 simple steps, i hope this will help you.
1.How to implement custom url schemes
Official docs
Helpful link
2.How to handle custom URL scheme with params in app delegate
handle the custom url and read params in appDelegate in this function
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if let query = url.query {
//that's my logic. yours url may be different
let components = query.components(separatedBy: "=")
print(components)
}
}
let me know if you need any help

How to use deep-linking same as facebook in iOS?

I want to use deep-linking , for example consider my post url is http://myappsite/api/video/post_id , how can I implement deep-linking using this link. as facebook is doing with this url https://www.facebook.com/page_name/videos/post-id
You need to implement universal links on website and app.
You can also use Branch to help you integrating universal links / deep linking.
You need link you mobile app and website by universal links and than you need parse url inside you ios code and open correct screen
You have to implement Universal linking for acheaving this type of functionality. This would give you a good start .
https://medium.com/#abhimuralidharan/universal-links-in-ios-79c4ee038272
After that, when you click on the link, your application will open and following delegate function called in AppDelegate.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
print("Continue User Activity called: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url and open whatever page you want to open.
}
return true
}
The url.absolutelyString return the url string on which you tapped. Chop out your video_id and open the appropriate ViewController.

Firebase iOS / Swift and Deep Links

We have just integrated firebase, and all of a sudden our deep links are no longer working. We're using AppAuth for authentication, so we're reliant on deep links to direct us to the right place. I'm getting the following error:
<Debug> [Firebase/Analytics][I-ACS023001] Deep Link does not contain valid required params. URL params: {...}
Initialization of firebase as follows:
let bundleId = Bundle.main.bundleIdentifier
let filePath = Bundle.main.path(forResource: "GoogleService-Info-" + bundleId!, ofType: "plist")!
let options = FIROptions(contentsOfFile: filePath)
FIRApp.configure(with: options!)
And here's the deep linking functions:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return application(app, open: url, sourceApplication: nil, annotation: [:])
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if url.host == AppHost.deeplink {
...
}
If i remove the call to FIRApp.configure, everything in the app works fine. My AppAuth redirects flow into the function above without any issue. However, with the call to configure(), it never gets into either one of the functions. As a result, i can't do a token exchange and complete authentication.
I suspected the AppDelegate proxy might be the issue, so i tried disabling it in the plist file. I've validated that the plist file passed to FIRApp.configure has the appropriate keys:
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
But no matter what i do, it's still activating the proxy:
[Firebase/Analytics][I-ACS003007] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
I'm using only FirebaseCrash and FirebaseCore (and FirebaseAnalytics indirectly through crash)
Instead of adding the FirebaseAppDelegateProxyEnabled key to the GoogleServices-Info.plist, add it to your App's info.plist. The Google Services plist should not be modified once it's generated.
As for disabling the proxy, it's fine to do this long term. The proxy is a convenience thing (it's just swizzling some methods), and you can reimplement it manually. There's some examples here of how to handle the lack of the proxy (non-swizzling case).

How to launch our app when we click a link in gmail

I am sending a link after signing up to the account from which user has signed up.
Now I want that when user click on that link from the corresponding account then he/she will move to app.
is there any way to launch our app from link clicked on gmail app?
Please help...
Thanks
You need to do perform Universal Linking.For universal linking you need to first create a “apple-app-site-association” file, which look like this :->
{
"applinks": {
"apps": [],
"details": {
"appID": "9JA89QQLNQ.com.apple.wwdc": {
"paths": [
"/wwdc/news/",
"/videos/wwdc/2015/*"
]
}
}
}
}
The applinks tag determines which apps are associated with the website. Leave the apps value as an empty array. Inside the details tag is an array of dictionaries for linking appIDs and URL paths.
The appID consists of your team ID combined with the app’s bundle ID.
After creating file you need to upload it on your domain like www.yourHost/apple-app-site-association.
now you need to go capabilities -> Associated Domains add here a link which you want to make universal i.e, which link you want to tappable to open your app.
Then you need to add this method in your app delegate class.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
//code here to related universal links
/* The activity type used when continuing from a web browsing session to either a web browser or a native app. Only activities of this type can be continued from a web browser to a native app.
*/
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}
//do something
return true
}
Here is the use of URL scheme, you can add it to your application in the info plist file.
And use the below delegate to catch the response
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
You just asked for the details so this tutorial will help you

iOS 9 safari iframe src with custom url scheme not working

I use this solution https://gist.github.com/davidwkeith/2662899 to redirect from web page into my app if app installed.
But it doesn't work on iOS 9. It's still working in Google-chrome. But iframe with custom URL scheme can't launch the application from Safari.
If I replace
document.getElementById('loader').src = 'custom-protocol://my-app'
(where loader is iframe) with
window.location = 'custom-protocol://my-app'
it will work.
os: iOS 9 beta4 and beta5
Anybody knows this problem? Is it iOS 9 beta bug? Or it will not be fixed?
The previous answer is a partial implementation of Universal Links that is missing critical details and doesn't include a fallback to the App Store.
First, you can no longer set iframe src in order to trigger a URI scheme. You've correctly identified that issue. As you noted, you can, however, still set window.location = 'custom-protocol://my-app';. So if you know that a user has your app because you've previously opened their app from the browser and have a cookie stored that can be looked up on your backend, you can still safely fire custom-protocol://.
Second, you can detect the user agent string using navigator.userAgent. Pre-iOS 9 you can still use the iframe to fire a URI scheme, then fallback after a timeout. On iOS 9, you can choose whether to fire the URI scheme or not based on cookies, then take the user to the App Store. I work on this at Branch and making use of cookies to recall whether a user likely has the app is something we've implemented. Feel free to reach out if you have more questions about that, or make use of our solution directly.
Implementing Universal Links is not quite as simple as the other answer describes. In reality, there is considerably more complexity. Here's a complete list of steps (I've helped several apps integrate in recent weeks using these steps):
1. Configure your app to register approved domains
i. Registered your app at developer.apple.com if you haven't
ii. Enable ‘Associated Domains’ on your app identifier on developer.apple.com
iii. Enable ‘Associated Domain’ on in your Xcode project
iv. Add the proper domain entitlement, applinks:yourdomain.com, in your app
2. Configure your website to host the ‘apple-app-site-association’ file
i. Buy a domain name or pick from your existing
ii. Acquire SSL certification for the domain name (you can use CloudFlare for this!)
iii. Create structured ‘apple-app-site-association’ JSON file
{
"applinks": {
"apps": [ ],
"details": {
"TEAM-IDENTIFIER.YOUR.BUNDLE.IDENTIFIER": {
"paths": [
"*"
]
}
}
}
}
iv. Sign the JSON file with the SSL certification
v. Configure the file server
The apple-app-site-association file:
- must be sent with the header ‘application/pkcs7-mime’
- must be sent from the endpoint youdomain.com/apple-app-site-association
- must return a 200 http code.
Example Express+Node:
var aasa = fs.readFileSync(__dirname + '/static/apple-app-site-association');
app.get('/apple-app-site-association', function(req, res, next) {
res.set('Content-Type', 'application/pkcs7-mime');
res.status(200).send(aasa);
});
credit: borrowed liberally from this blog post
Yes with iOS9 now you can deep link. Check the link for detailed explanation but I laid out the basics.
http://blog.hokolinks.com/how-to-implement-apple-universal-links-on-ios-9/
first you must go to your target and click capabilities. Add the associated domain.
Next you must upload apple-app-site-association file.
Basically open a JSON editor and construct something like this
{
"applinks": {
"apps": [],
"details": {
"TBEJCS6FFP.com.domain.App": {
"paths":[ "*" ]
}
}
}
}
Next you must support Univeral links in your app. You need to implement
extension AppDelegate {
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let webpageURL = userActivity.webpageURL! // Always exists
if !handleUniversalLink(URL: webpageURL) {
UIApplication.sharedApplication().openURL(webpageURL)
}
}
return true
}
private func handleUniversalLink(URL url: NSURL) -> Bool {
if let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true), let host = components.host, let pathComponents = components.path?.pathComponents {
switch host {
case "domain.com":
if pathComponents.count >= 4 {
switch (pathComponents[0], pathComponents[1], pathComponents[2], pathComponents[3]) {
case ("/", "path", "to", let something):
if validateSomething(something) {
presentSomethingViewController(something)
return true
}
default:
return false
}

Resources