opposite of openURL to close web - ios

How do I close openURL once I open it?
I'm looking at the docs but there's no other method listed
https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623073-application?language=objc
I can open it below
UIApplication.shared.open(authURL, options: [:], completionHandler:nil)
but is there a function to close it programatically

When you call that method, the OS switches to the Safari app and passes it the URL you provided. Once you call that method, you no longer have control and the user has to get back to your app on their own.
You might want to look into presenting a SFSafariViewController instead to keep the user inside your app.

Related

Can't call INPauseWorkoutIntent without home button

I have implemented INPauseWorkoutIntent, INStartWorkoutIntent or INResumeWorkoutIntent in my app in IOS 12 and XCode 10. I can use the commands correctly with using home button to open Siri but what I need is Hand off. I mean, I just want to say "Pause workout" and it should pause. I also don't want to use watch. How to achieve that, what am I missing?
Note: - (id)handlerForIntent:(INIntent *)intent not called anyways.
I believe you already have implemented resolve, confirm, and handler functions comforting to respective protocols.
I just check response code for workout and they have .continueInApp response code.
That being said, I believe you can pass response with code .continueInApp and save whatever parameters you have to use in UserActivity in handler's completion. UserAcitivity will be passed to application: continueUserActivity function in AppDelegate; so you can pause it from there.
If handlerForIntent is not called, then I believe intent is not understood by Siri

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

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.
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.
Here's swift 4.2 version of Ricardo's own solution
let userActivity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
userActivity.webpageURL = url;
UIApplication.shared.delegate?.application?(UIApplication.shared, continue: userActivity, restorationHandler: { _ in })

Return to sourceApplication after openUrl request is completely handled

I'm implementing an iOS app that handles a custom protocol.
Writing the method application(openURL:sourceApplication:annotation:) in my AppDelegate was easy but I'm left with a problem: I want that - once the user have done with the request - my app move to the background and send the user back to the caller sourceApplication (e.g. a browser, a QRCode reader, or any another app).
This is just like the difference between "tel:" and "telprompt:" url calls: in the former case the phone app remains active, in the latter case, after the call, the user is send back to the sourceApplication.
In order to let my app handle my custom protocol like "telprompt:" does, the only way I can think about is terminate the app once the user action is completed... but this is against iOS Human Interface Guidelines (they say "Don’t Quit Programmatically") and my app can be rejected by Apple.
On Android it is easy: you respond to an Intent with an Activity and when you call finish() on that activity the user is back to his previous app/browser/whatever.
Anyone knows a good way to achieve this on iOS?
Just to clarify:
my app don't call openUrl, it responds to openUrl requests from browser, QRCode reader, other apps;
I don't have to make phone calls;
when I handle a request I ask the user for some data, contact a server, and that's it: the interaction is finished and it would be very nice to drive the user back to previous app without let him use the home button.
I believe you should call openUrl when you are done, with the source app url in param.
That's what facebook does when you use the "connect with facebook" API.

Ios 8: Determine the destination app when my app goes to the background?

I override my app's openURL-method to know when we're about to leave the app from an ABPersonViewController, the reason being that that class doesn't notify its delegate on all of the actions it presents to the user. If it did everything would be fine.
This worked flawlessly in iOS 7, but when trying this in iOS 8.1 it turns out that the ABPersonViewController doesn't call openURL for all its actions anymore. For instance, tapping a phone number gets me to the phone app without calling openURL. Tapping the SMS bubble on the other hand will call openURL.
When tapping the facebook profile entry (with the URL "fb://profile/1234567890") the log says that "Launch Services" doesn't have a registered handler for the scheme "fb". So I'm assuming that calls to Launch Services have replaced the calls to openURL. I can't find out much more about it other than that it's "a private API".
Is there a way to detect these calls? Or, is it possible to override handlers for known schemes like "tel" and "mailto" internally for my app? I basically just need to know when we're leaving the app and where we're going.

Resume app after call

I am allowing user to call from my app. Is there any way to resume my app back after the call ends?
In know "telprompt" url and "UIWebView" but I don't want to use those because they both pop up to confirm call.
I am looking something automatic like "tel" URL, but I want it to return to my app after the call.
No. Even if you registered a custom url scheme for your app (say, myappname://), the Phone app will not invoke it after the call ends.

Resources