When the icon of my Safari app extension icon is touched, I want to change the URL without showing a new view. Doing this comes down to two issues:
How can I use an safari app extension without showing a new view? I just want to perform a background action when the extension icon is pressed.
How can I change the current URL in Safari?
Actually, you might be able to change the URL at the finalize function of your ExtensionPreprocessingJS file
// Note that the finalize function is only available in iOS.
finalize: function(arguments) {
// arguments contains the value the extension provides in
[NSExtensionContext completeRequestReturningItems:completion:].
// In this example, the extension provides a color as a returning item.
document.URL = arguments["newUrl"];
}
It seems like what you're describing is a bookmark, and not an app extension. I would highly doubt that app extensions would allow you to interface with Safari and update the URL, this would be wrong in many regards, including privacy and security. In short, not possible (sorry).
Related
We currently support wildcarding for Universal Links. So my applinks looks like: applinks:*.company.com.
Let's say I want to only handle a link if it is https://company.com/?query1=abc
Let's say I instead tap on a link that is https://company.com/?query1=123
Since the condition is not met, I want to ignore this link and prevent my iOS App from responding to it. Is this possible?
I thought I'd just be able to return false in continue:restorationHandler but that does not prevent the iOS App from opening.
Returning false from application(_:continue:restorationHandler:) doesn't result in the URL being passed back to Safari (as you have discovered). The documentation states:
If you don't implement this method or if your implementation returns false, iOS tries to create a document for your app to open using a URL
So returning false just results in iOS trying to launch your app in a different way.
What you can do is call open(_:options:completionHandler:) and pass the URL you received. The URL will then be opened in Safari; iOS won't pass your app a universal link that your app opens itself because that could create an infinite loop.
I'm currently developing an app and i'm trying to add a button which would open another app installed on my phone when the button is tapped
I've tried looking for the URL scheme for the app but i can't find it. Only thing i can find is the bundle ID. So i thought maybe there's a way to use the bundle ID to open the app through private APIs in Swift? My phone is jailbroken if that helps. Below is my code
#IBAction func openAppTapped(_ sender: Any) {
UIApplication.shared.openURL(NSURL(string: "itms-apps://itunes.apple.com/us/app/apspace/id1413678891?mt=8")! as URL)
}
I managed to upon the app on the appstore upon tapping the button but i want a way to open the app directly without using url schemes but instead using the bundle id and/or private APIs. Any help would be really really appreciated!
To open another app, you are either going to have to use some kind of extension provided by that app or figure out their URL scheme and reverse engineer it.
The first thing you could try is looking at the app's Info.plist and seeing if they have defined a URLScheme for their app. If not, and they haven't implemented an extension, then I think you're SOL.
If they did define it, try using it to open their app and see what happens, they might have some code that rejects or accepts a request to open their app based on the format of the URL after their scheme. If you can't figure it out with trial and error, you could use the fact that your phone is jailbroken to decompile their app and hunt down the URL parsing logic which is likely in their AppDelegate. From there you could try and build a URL that you can use to successfully open their app every time.
Working on the first swift app, and stuck in "share extension". Trying to share a phone number from recent calls log to an app for background task.
Thought to do it in this way, once user enter profile of a number from recent call log:
Will see the icon of my app:
Now want to get the phone number and the country code to do that task, current code is:
class ShareViewController: UIViewController {
override func viewDidLoad() {
// Want to get selected phone number only and print it on the console for testing
print("Test\n")
}
}
How to do that?
Thanks in advance
Your App's icon is used. From Apples documentation:
In iOS, a custom Action extension uses a template image version of its containing app’s icon, which you must provide.
iOS Share extensions automatically employ the containing app’s icon. If you provide a separate icon in your Share extension target, Xcode ignores it. For all other app extension types, you must provide an icon that matches the containing app’s icon.
How to detect in which app my custom keyboard used and show different button?
E.g. in Twitter I would add # to string I post into input field and in Reddit /r/
It is possible through following code. As you'll get bundle identifier of the app where you're using your custom keyboard.
Swift
let hostBundleID = self.parentViewController!.valueForKey("_hostBundleID")
let currentHostBundleID = String(hostBundleID)
print(currentHostBundleID);
From bundle identifier you can find app name easily.
Edit: See above. Things have changed.
This is not possible. An extension runs sandboxed and is only fed information from the API and cannot access anything else. The keyboard can only receive text context changes and activate/deactivate calls. Being able to detect an app lies outside of the extension sandbox and therefore is impossible.
My issue is I need to find a way where I can have my action extension run in Safari and open up the website currently being viewed in Safari in my app (my app is a special web browser).
Here's a screenshot:
When the rED extension is clicked, the extension opens up "rED://" which is my custom URL scheme. This launches the app and everything works fine.
However, I want the extension to grab the URL of the webpage being viewed in safari and open that website in my app, so the URL scheme call would look something like "rED://google.com".
What sort of code/methods would I need to implement, and in which .m file would it go in?
Apple provides a method on NSExtensionContext for opening apps via URLs, however that only works for Today extensions (verified by an Apple employee at https://stackoverflow.com/a/24709883/3943258). This technically isn't currently possible.