How to generate links for sharing in iOS? - ios

I want share url of product, product name to some user using either what's app or facebook etc.when user clicks on that product, same product page in app should be opened if app is installed. if app is not installed it should navigate to app store.Now how to generate that sharable link so that same page in app should be opened when user clicks?

To solve this issue you need to implement Universal link.
Add applink: in Target-> Capablities ->Associated Domain -> Domains -> Add server url
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
}
See the following post for more information
https://medium.com/#abhimuralidharan/universal-links-in-ios-79c4ee038272

Related

Universal linking with website by using swift

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.

Testing passwordless auth in Firebase test lab for iOS

I am trying to figure out how to perform e2e test via firebase test lab for iOS that allow to check passwordless authentication flow, which essentially should do following
Enters email within my app
Firebase sends auth link to such email
Somehow I need to be logged into such email somewhere in firebases test device, I assume either in mail app, or gmail?
I need to know when new email arrives and open it
Once I opened an email I need to click on auth link
This should bring me back into the app and authenticate
My biggest issue at the moment is figuring out steps that happen outside my app i.e. how can I prepare for this test and log in under my email address (is it better to log into gmail in safari for example or somehow add this acc to apples mail app?).
Testing email
In my experience, testing your own code to see if an email was sent is not straightforward beyond checking if the method call you expect to send the email has happened.
Add on top of that using Firebase, which does not expose its underlying email send code, and that looks like a challenge to me.
In terms of testing, I suggest you assert that your method calls to send email happened or that the relevant code path was reached. In Firebase web, this looks like:
firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings)
.then(function() {
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
window.localStorage.setItem('emailForSignIn', email);
// TODO save email to something accessible in your iOS tests
// TODO In your tests, confirm that email was saved after it was sent
})
.catch(function(error) {
// Some error occurred, you can inspect the code: error.code
});
See: https://firebase.google.com/docs/auth/web/email-link-auth#send_an_authentication_link_to_the_users_email_address
Another option:
You could setup a test user with an email address on a mail server that you manage, and check for incoming mail for that test user with your own custom mail reading code.
I would use Firebase Admin tools for this: https://firebase.google.com/docs/auth/admin/manage-users#create_a_user
I think you should first take a look at firebase docs for iOS on how to create dynamic links that you can use for email auth.
https://firebase.google.com/docs/auth/ios/email-link-auth
https://firebase.google.com/docs/auth/ios/passing-state-in-email-actions#configuring_firebase_dynamic_links
After you're done with those two check out the following code:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// [END old_delegate]
if handlePasswordlessSignIn(withURL: url) {
return true
}
}
func handlePasswordlessSignIn(withURL url: URL) -> Bool {
let link = url.absoluteString
// [START is_signin_link]
if Auth.auth().isSignIn(withEmailLink: link) {
// [END is_signin_link]
UserDefaults.standard.set(link, forKey: "Link")
(window?.rootViewController as? UINavigationController)?.popToRootViewController(animated: false)
window?.rootViewController?.children[0].performSegue(withIdentifier: "passwordless", sender: nil)
return true
}
return false
}
This is just an example on how you can handle the deep link in your app after the user taps the link. The delegate method
func application(_ application: UIApplication, open url: URL,
sourceApplication: String?, annotation: Any) -> Bool
in AppDelegate is used for all deep links into an app. You could set up for example your own scheme that your app conforms to. And you can send url type links with your custom scheme into your app from the browser for example.
To do this just Open Xcode, go to Project Settings -> Info, and add inside ‘The URL Types” section a new URL scheme. Add something of the sort of com.myApp in order for it to be as unizue as possible. Then you can just type into a browser com.myApp://main and handle that in the appDelegate.
Edit: It says so in their docs that you can present a prompt inside the app for the user to input the email. Where the user opens his email from isn't really your concern as long as your dynamic link is set up properly.

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

Resources