Open iOS app from Safari after downloaded - ios

How do you configure your app to open from safari after it has already been downloaded? In the screenshot below when clicking "Open" it opens the app in the App Store, even after the app is downloaded.
I've implemented continue userActivity in the appDelegate class:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let url = userActivity.webpageURL {
self.continueWithLink(url: url)
}
return true
}
What else do I need to do to make it function properly?

Related

Universal links not working correctly in IOS App - Not opening the correct page

I have an IOS App that requires a member login. I've set up a separate page for new members to log in. When I email them to confirm their new account, I want the link in the email to go to the login page in the app, which is "newlogin.php'. While testing this with Safari on my iPhone and iPad, I have tried almost everything to get this to work, but the link keeps going to the home page in the app, which is mydomain.com.
In the Associated Domains section of Xcode, I entered: applinks:mydomain.com.
Here is my apple-app-site-association file, which is in both the root directory and the .well-known directory:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "TEAMID.com.-mydomain.MyDomain",
"paths": ["/newlogin.php"]
}
]
}
}
And here is the function for the AppDelagate file that I have been struggling with for several days:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
{
// ?????????????????????????????????
}
At this point, I have no clue what to put in the function where the question marks (???) are entered, in order to make this go to domain.com/newlogin.php. Please, someone help me. I've been at this for several days, and it's starting to get to me. Thank you very much in advance.
First you will check what is the activity type where you will know you are coming from web or not.
Then get url from where you come and do necessary actions based on url.
Check below code.
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?
) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print("The url : " ,url)
// now do what you want with url
check if url contains .login.php, take user to login page in your app.
}
return false
}
Assuming you're not using SceneDelegate's, You need to register both delegate functions in your AppDelegate.swift file.:
// MARK: - URL
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard let incomingURL = userActivity.webpageURL else { return false }
// Do something with `incomingURL`
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// Do something with `url`
return true
}

iOS Universal Linking is not Working in swift

I having the Universal linking in my application.
I place my Association file code into the server with the help of backend
Please find My URL: https://www.furnitureinfashion.net/apple-app-site-association/
Whenever I check the domain validation here: https://branch.io/resources/aasa-validator/?domain=https:%2F%2Fdevapp.meet2talk.com#resultsbox
It will show everything is fine, but when I pick on my base URL in safari it cants working.
Anyone suggest to me how do we resolve this issue.
I write the following delegate method in AppDelegate
private func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool
{
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
let userurl = url.absoluteString
print(userurl)
}
return true
}
Here I add the App Capabilities also.
Capabilities

NSUserActivity: Which method will be called when user will tap (or will make call ) from recent log of my app?

I am implementing CallKit in swift and I'm facing a problem with NSUserActivity while making a call directly from the recent log.
While tapping on my app entry in the recent log, my app is launching but any method of AppDelegate is not calling.
I have turned on Siri from application capabilities and have added NSUserActivityType in info.plist. I've added INStartAudioCallIntent and INStartVideoCallIntent inside NSUserActivityType. The method I've implemented inside AppDelegate class is the following:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
print("Restoration")
return true
}
When tapping on any entry of my app from the recent log the following line is printed in the debugger console.
AppDelegate-BAA416CD-ED84-4161-A054-B2192AFAD47A application:continueUserActivity:restorationHandler:] has an interaction attached but it is not handled
Change the signature of the function, i.e. the restorationHandler parameter type from ([Any]?) -> Void to ([UIUserActivityRestoring]?) -> Void
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
//if its a call
guard let handle = userActivity.startCallHandle else {
print("Could not determine start call handle from user activity: \(userActivity)")
return false
}
}
For more details:
https://github.com/Lax/Learn-iOS-Swift-by-Examples/blob/master/Speakerbox/Speakerbox/AppDelegate.swift
I changed the signature and it worked for me.

How to know user is coming into app by using of Universal links

I using Universal linking in my application.
When the user pick on link directly move into root view controller.
But I want to change the rootviewcontroller when user entering through Universal link.
please help to those delegates methods.
There is 2 delegate method that will fire when application is open from link or user tap link as per below.
Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// handler for URL Scheme "This will called for URL schema"
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// handler for Universal Links "This will called for Universal Link"
return true
}
Use this delegate method:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool

After opening iOS app "continue userActivity:" method isn't called - Firebase dynamic link

I have successfully integrated Firebase dynamic links and when I click on dynamic link then my app is opening.
The issues I'm facing is after opening app from dynamic links, continue userActivity: method should be called, but nothing happens.
I've checked the all the possible thing but didn't recognised the issue.
I've searched the SO for this but none of the answer helped me.
My Code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
GIDSignIn.sharedInstance().clientID = kGoogleSignInClientId
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
// DynamicLinks.performDiagnostics(completion: nil)
FirebaseApp.configure()
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if url.absoluteString.contains(kFBAppId) {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
print(dynamicLink.url ?? URL(string: "test") as Any)
return true
}
return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[.sourceApplication] as? String, annotation: options[.annotation])
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
//This method is not getting called
}
Additional answer for those using separate SceneDelegate.swift apart from AppDelegate.swift:
This method in AppDelegate >
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == CSSearchableItemActionType {
}
is now in SceneDelegate >
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
}
I don't know whether they keep their doc. up to date or not.
I have just copy-pasted the code from the Google's official Firebase dynamic link document.
Why was the continue userActivity: method is not called?
The reason is (See the difference in following method)
Copy pasted from google doc. - Wrong one
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
}
I wrote this (without copy paste from google doc.) - Correct one
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
}
I've made bold the difference.
This is what I was trying for many hours. It is really very frustrating for me to blindly trust on google doc.:-|
Hope this may help other.
You need to check two times.
When app. is running in the background and is opening from Link:
Delegate method is:func checkForTransferedTicket(_ userActivity: NSUserActivity) { }
When app. is NOT running in background and is opening from Link:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions) { if let userActivity = connectionOptions.userActivities.first {
print(userActivity)
}
}

Resources