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.
Related
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.
I have referred How can I place a WhatsApp call from an iOS app? which states that this feature is currently not available in iOS and as per WhatsApp FAQ Share Extension (Custom URL Scheme) it has still not mentioned any schema for placing a call, document it has mentioned:
Placing a WhatsApp call(voice call VOIP)
To make a WhatsApp call, simply open the chat with the person you want to call and tap Call in the top right corner.
Whatsapp FAQ Here
But placing a WhatsApp call from android is possible, Which I could not find in iOS.But placing WhatsApp call feature is available from phone contacts.
So my doubt is whether it is currently available in iOS to place a WhatsApp (voip)voice call from my iOS app?
If possible can you please suggest me with url schema(if available) for this just like place a chat from my app like this #"whatsapp://send?text=Hello%2C%20World!" as I couldn't find this?
I have google it and searched a lot on stackoverflow and https://faq.whatsapp.com
Seems like currently, video call from contact book feature is limited to OS level only.
But you can open particular contact then user has to manually tap on video call button.
This is regardless of phone no is stored in contact book or not. ( You can directly open )
I have tried this in Swift 3 code.
if #available(iOS 10.0, *) {
UIApplication.shared.open(NSURL(string: "whatsapp://send?phone=+91phonenumber")! as URL)
} else {
UIApplication.shared.openURL(NSURL(string: "whatsapp://send?phone=+91phonenumber")! as URL)
}
https://faq.whatsapp.com/en/iphone/23559013
Hope this helps you to figure out further way
i'm new to swift, i have created a today widget , and i added a button to that. in the Action of that button, i want to launch a url in safari, but "sharedApplication( )" doesn't working, i'm using this code in Normal view controller :
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.sharedApplication().openURL(NSURL(string: "facetime:mahdi#gmail.com")!)
// Do any additional setup after loading the view, typically from a nib.
}
but its not working in Today App Extension.
You can't use sharedApplication from an app extension.
Today widgets can open urls using the openUrl:completionHandler: method on NSExtensionContext, so you could do:
extensionContext?.openURL(NSURL(string: "facetime:mahdi#gmail.com")!, completionHandler: nil)
You should be doing this in the tap handler for your button though, not in viewDidLoad.
But note that the apple documentation states:
IMPORTANT
Apple allows any Today widget to use the
openURL:completionHandler: method to open the widget’s own containing
app.
If you employ this method to open other apps from your Today widget,
your App Store submission might entail additional review to ensure
compliance with the intent of Today widgets.
To learn more, read App Store Review Guidelines and iOS Human
Interface Guidelines, linked to from Apple’s App Review Support page
This is well documented. There is no sharedApplication() in a Today extension; the code isn't running in your app. In this particular situation, you can communicate with the NSExtensionContext instead.
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.
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).