How to programmatically make phone call from apple watch app? - xcode

My Watch app has list of contact and I want open initiate call from watch. like we do in iPhone device.
I have tried this solution but not working for.

I have fixed it using following method
var phone = "123456"
if let telURL=NSURL(string:"tel:\(phone)") {
let wkExt=WKExtension.sharedExtension()
wkExtension.openSystemURL(telURL)
}

Swift 4 / WatchOS 5
var phone = "1234567890"
if let telURL = URL(string: "tel:\(phone)") {
let wkExt = WKExtension.shared()
wkExt.openSystemURL(telURL)
}

Related

macOS Accessibility Inspector does not work with Slack

When I'm using macOS's Accessibility Inspector on apps like notes and Apple mail, I get all the window's children elements. If I use the Inspector on Slack, though, I only get the window and nothing of the content.
Is there a way to force slack to expose its children to the inspector somehow?
Same goes for WhatsApp Web and the Apple Pages Canvas.
Found the answer here https://www.electronjs.org/docs/latest/tutorial/accessibility#macos
The AXManualAccessibility Attribute of the App must be set to kCFBooleanTrue.
This is how it's done:
Get the process ID of the current app
Create an AXUIElement from the app using the process ID
Set the AXManualAccessibility of the newly created AXUIElement to kCFBooleanTrue
Now all elements of the App are inspectable using the Accessibility manager. This not only works for all electron apps, but also apps like Pages or MS Word.
Swift
let kAXManualAccessibility: CFString = "AXManualAccessibility" as CFString;
private func enableAccessibility() {
guard let processIdentifier = NSWorkspace.shared.frontmostApplication?.processIdentifier else { return }
let appRef = AXUIElementCreateApplication(processIdentifier)
AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, kCFBooleanTrue)
}
Objective C
CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");
+ (void)enableAccessibility:(BOOL)enable inElectronApplication:(NSRunningApplication *)app
{
AXUIElementRef appRef = AXUIElementCreateApplication(app.processIdentifier);
if (appRef == nil) return;
CFBooleanRef value = enable ? kCFBooleanTrue : kCFBooleanFalse;
AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, value);
CFRelease(appRef);
}

Why is UIDocumentPickerViewController working on iOS, but showing the wrong folder on Mac Catalyst?

The code below works fine on an iPad or iPhone -- saveDocument() (see below) writes to /Users/me/Library/Containers/My-App/Data/Documents, and openDocument() shows me the content of that folder.
On macOS, however, openDocument() shows the Documents folder at the root level of iCloud Drive, not the sandboxed version, which is local to my computer
It's like the documentPickerVC.directoryURL is being ignored. Why is that?
If it helps, the documentURL looks like this:
file:///Users/me/Library/Containers/org.me.My-App/Data/Documents/
Any help would be really, really appreciated!
func saveDocument(){
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let puzzleData = try? encoder.encode(puzzle)
print("Saving: \(documentURL)")
let saveableURL = documentURL!.appendingPathComponent("\( .puzzle.date)")
try puzzleData!.write(to: saveableURL)
} catch {
displayError(title: "Error while saving document", message: "There was an error: \(error)")
}
}
// when the user taps on the Open button
#objc func openDocument(){
documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: [UTType("public.item")!, UTType("public.data")!], asCopy: true )
documentPickerVC.delegate = self
documentPickerVC.modalPresentationStyle = .formSheet
documentPickerVC.directoryURL = documentURL
self.present(documentPickerVC, animated: true)
}
So, the reason documentURL isn't working is because Apple doesn't support it: specifically, “ This property has no effect in Mac apps built with Mac Catalyst.”

Xamarin Android Background Notification Custom Sound

is it possible to use custom sounds in xamarin android for background notification? I didnt find any examples.
Yep! Here's an example:
var pathToPushSound = $"android.resource://com.your.package/raw/{soundName}";
var soundUri = Android.Net.Uri.Parse(pathToPushSound);
var builder = new NotificationCompat.Builder(_context)
.SetContentTitle("TITLE")
.SetContentText("TEXT")
.SetPriority(1)
.SetSmallIcon(Resource.Drawable.TransparentLogo)
.SetOngoing(true)
.SetSound(soundUri);
builder.Build();
The URI is the path to the resource where your sound file lives, then you set that URI in your NotificationBuilder using the SetSound method.

xamarin ios 10 open app store application programmatically in my app

i'm trying to open app store application programmatically in my app.
what i'm trying to do is that i'm calling a service to check at the current app version and if it needs update i should open app store application to let the user update the my app.
note: the app not published yet to the store, i'm still in coding phase.
i tried to use the following code in ViewDidLoad method, but it's not working (nothing happened):
var nsurl = new NSUrl("itms://itunes.apple.com");
UIApplication.SharedApplication.OpenUrl(nsurl);
A direct link via itms: will only work in an actual device, if you are testing on a simulator, use https://itunes.apple.com/us/genre/ios/id36?mt=8 instead.
I would recommend using itms:// link on the actual device as it prevents the redirects that user sees when using a https:// link to open iTunes.
bool isSimulator = Runtime.Arch == Arch.SIMULATOR;
NSUrl itunesLink;
if (isSimulator)
{
itunesLink = new NSUrl("https://itunes.apple.com/us/genre/ios/id36?mt=8");
}
else
{
itunesLink = new NSUrl("itms://itunes.apple.com");
}
UIApplication.SharedApplication.OpenUrl(itunesLink, new NSDictionary() { }, null);
Instead of opening the external Store app on the device, you might want to consider keeping the user inside of your app by using a SKStoreProductViewController:
bool isSimulator = Runtime.Arch == Arch.SIMULATOR;
if (!isSimulator)
{
var storeViewController = new SKStoreProductViewController();
storeViewController.Delegate = this;
var id = SKStoreProductParameterKey.ITunesItemIdentifier;
var productDictionaryKeys = new NSDictionary("SKStoreProductParameterITunesItemIdentifier", 123456789);
var parameters = new StoreProductParameters(productDictionaryKeys);
storeViewController.LoadProduct(parameters, (bool loaded, NSError error) =>
{
if ((error == null) && loaded)
{
this.PresentViewController(storeViewController, true, () =>
{
Console.WriteLine("SKStoreProductViewController Completed");
});
}
if (error != null)
{
throw new NSErrorException(error);
}
});
}
else
{
var itunesLink = new NSUrl("https://itunes.apple.com/us/genre/ios/id36?mt=8");
UIApplication.SharedApplication.OpenUrl(itunesLink, new NSDictionary() { }, null);
}
NSBundle.MainBundle.InfoDictionary["CFBundleVersion"]
Returns you the current app version.
To open the Apple Appstore just let the user navigate to the appstore link, Apple will automaticly detect that the user is using an iPhone and will open the Appstore for them.
Test yourself:
Open the following link in safari: Whatsapp in the Appstore
It will automatically open the appstore.
When you create app on iTunesConnect you can get url to your future app in AppStore even if you didn't release it yet. You can find it under App Information tab:
In your app you can just open it:
var nsurl = new NSUrl("https://itunes.apple.com/us/app/mygreatapp/id123456789");
UIApplication.SharedApplication.OpenUrl(nsurl);

Swift : Share text through Twitter

So basically I am making an event app. Everything has been going smoothly but there's just sharing the event to twitter.
I have searched the internet but all I am getting is using the native app of twitter which I don't want. I want to use the browser to tweet.
I have implemented this method for FB sharing.
Any idea would help me a lot.
let content = FBSDKShareLinkContent()
content.contentURL=NSURL(string: "http://facebook.com")
content.imageURL = NSURL(string: "http://facebook.com")
content.contentTitle = "Shou 3emlin test app "
content.contentDescription = "testing testing testing"
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.mode=FBSDKShareDialogMode.Browser
shareDialog.shareContent = content
if !shareDialog.canShow() {
shareDialog.mode=FBSDKShareDialogMode.Native
shareDialog.shareContent = content
}
if shareDialog.canShow() {
shareDialog.show()
}
Put this in an action method of a button or in the method where you want to use the browser to tweet your text Swift 3.0:
let tweetText = "your text"
let tweetUrl = "http://stackoverflow.com/"
let shareString = "https://twitter.com/intent/tweet?text=\(tweetText)&url=\(tweetUrl)"
// encode a space to %20 for example
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
// cast to an url
let url = URL(string: escapedShareString)
// open in safari
UIApplication.shared.openURL(url!)
Result:
Take a look at Fabric.io. This SDK allows you to compose tweets directly from your app.
let composer = TWTRComposer()
composer.setText("just setting up my Fabric")
composer.setImage(UIImage(named: "fabric"))
// Called from a UIViewController
composer.showFromViewController(self) { result in
if (result == TWTRComposerResult.Cancelled) {
print("Tweet composition cancelled")
}
else {
print("Sending tweet!")
}
}
let tweetText = "hy"
let tweetUrl = "http://rimmi/"
let shareString = "https://twitter.com/intent/tweet?text=\(tweetText)&url=\(tweetUrl)"
// encode a space to %20 for example
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
// cast to an url
let url = URL(string: escapedShareString)
// open in safari
UIApplication.shared.openURL(url!)
#ronatory's solution worked like charm. It also opens a Twitter application if it's already installed on the user's device.
For swift 5+ use UIApplication.shared.open(url!) instead of UIApplication.shared.openURL(url!) as it's deprecated.

Resources