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.
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.
this question is a lot like Share data between two or more iPhone applications except:
I'm looking for a way to do this in an iOS 8+ (or 9+) application using swift
I want to be able to use the sound file contained in the first app so the easter egg I'm making is only available when the user has both apps installed
since this is part of an easter egg, i don't want to use any method that would cause anything extra to be displayed on screen such as a browser redirect or some kind of permission popup
(this basically rules out using the share sheet and custom url's to pass data as described in the post above)
I am using AVAudioPlayer and AVAudioSession in the first app to play the sound if that is at all helpful.
Use App Group
You can share actual NSData through the NSUserDefaults:
if let userDefaults = NSUserDefaults(suiteName: <group>) {
userDefaults.setObject(obj, forKey: key)
}
and retrieve from another app in the same group like so:
if let userDefaults = NSUserDefaults(suiteName: <group>) {
if let obj = userDefaults.objectForKey(key) {
// magic
}
}
It appears that the only limitation for passing data through the user defaults is the device storage capacity, and since NSUserDefaults accepts NSData as a storage format, it makes a prime candidate for sharing tidbits information.
If both apps are yours you can implement a custom url scheme in the second app, and then from the first app ask if it knows how to open an URL with that scheme. If the answer is yes, the app is installed. The function is called canOpenURL. It's an instance method of UIApplication.
I vaguely remember that in iOS 9 and later, Apple added a restriction that you have to register the URLs you are going to ask about in your info.plist, but I don't remember the details. That won't prevent this scheme from working, but it is an extra step you have to take.
I'm working on iOS app in which I need to integrate touch id and passcode, i googled and found many tutorials for touch id, I followed this and done successfully. Every thing fine but on popup which is saying Enter Password
as shown in following pic i have few queries.
Is it possible to use apple default passcode view as shown in lock screen?
If Yes, then will apple allow to upload app onto appstore?
Looking for help.
Thanks
to hide password option try this..
var LocalAuthentication = LAContext()
LocalAuthentication.localizedFallbackTitle = "" // Add this line
tutorial which you have mentioned is using only Biometrics authentication with deviceOwnerAuthenticationWithBiometrics which Indicates that the device owner authenticated using Touch ID refer this .
If you want to authenticate with any of one (Touch id or passcode) , use deviceOwnerAuthentication instead.
replace
[context .evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics ..
with
[context .evaluatePolicy(LAPolicy.deviceOwnerAuthentication ..
We can't use Apple's default lockscreen view inside our apps, However you can use this library on github.
We are trying to create a custom emoji keyboard in iOS 8. We already created a keyboard with our own icons. These icons have no Unicode characters. But I can't pass my icons with text. Is this possible using iOS 8? Why can't I send my own icons?
Brian is correct. The keyboard extension inserts by textDocumentProxy so you cannot use the images. A workaround would maybe be to use the pasteboard like below. Not ideal I know, but it is my only idea. I had this problem a few months ago and came to this same half solution. Keep in mind you will need to grant the keyboard access in the Info.plist file.
"RequestsOpenAccess" = YES in your Info.plist file. AND you have to toggle "Full Access" with settings.
let imageURL = NSBundle.mainBundle().pathForResource("emojiCustom", ofType: "png")
let data = NSData(contentsOfURL: NSURL(fileURLWithPath: imageURL!)!);
UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: "emojiCustom.png")
Then you will need to prompt the user that the custom emoji is available for pasting. I know it is a hack, and not a pretty one, but other than submitting your emojis to unicode for approval (and that would take a lot of time and it is just a proposal, they don't have to approve for adoption) you are limited to a type of hack. If you want to submit to unicode, I have included their link.
http://unicode.org/emoji/selection.html
A different approach that is now available under iOS 10 is their exposure of the iMessages API. You can use your "main" app to allow the user to build a custom emoji "image", or do it yourself and use the iMessage API to attach it directly to the message.
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).