how can I open WhatsApp from my app to a specific number. For Android, the following is working fine
But it didn't work in IOS. Whats App Open and then Show Message
(This Link couldn't be opened Check the link and try again)
Here is my code for shared Project:
try
{
if (await Launcher.TryOpenAsync(new Uri("whatsapp://send?phone=+" + mobile)))
await Launcher.OpenAsync(new Uri("whatsapp://send?phone=+"+ mobile));
else
await Rg.Plugins.Popup.Services.PopupNavigation.PushAsync(new ShowMessagePage("Install Whatsapp", 5000));
}
catch (Exception ex)
{
await Rg.Plugins.Popup.Services.PopupNavigation.PushAsync(newShowMessagePage(Helpers.TranslateExtension.Translate("Error"), 5000));
}
-- I Added That in info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
Use this code. Works for me in iOS
try
{
Launcher.OpenAsync("https://wa.me/999999999999?text=My%20message");
}
catch
{
}
Related
private async void SlidesCommandTapped(object obj)
{
if (!await Launcher.TryOpenAsync("com.microsoft.office.powerpoint://"))
{
await Launcher.OpenAsync(new Uri("market://details?id=com.microsoft.office.powerpoint"));
}
}
tryopenasync now working
if microsoft powerpoint app not present it opens playstore and tells you to install powerpoint app but right now if the app is installed too its going to playstore
Well your code should look something like below:
var isPowerPointAvailable = await Launcher.TryOpenAsync("com.microsoft.office.powerpoint://");
if (isPowerPointAvailable)
{
// this would change based on what file you want to open
await Launcher.OpenAsync("com.microsoft.office.powerpoint://");
}
else
{
await Launcher.OpenAsync(new Uri("market://details?id=com.microsoft.office.powerpoint"));
}
Goodluck,
Feel free to get back if you have queries
I am using Xamarin.Forms and written the code to download the file for the iOS
platform. It is downloading the file successfully without any error. But after downloading it, I am not able to find the downloaded file in my apple device.
During debugging I found that it is showing
/var/mobile/Containers/Data/Application/1234567A-B8CD-9EF9-C850-9G73587DC7C/Documents/XF_Downloads/hausmann_abcd.jpg
path. So at which location file get saved? below is the image for the same.
I have written below code for this
public class IosDownloader : IDownloader
{
public event EventHandler<DownloadEventArgs> OnFileDownloaded;
public void DownloadFile(string url, string folder)
{
string pathToNewFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), folder);
Directory.CreateDirectory(pathToNewFolder);
try
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
string pathToNewFile = Path.Combine(pathToNewFolder, Path.GetFileName(url));
webClient.DownloadFileAsync(new Uri(url), pathToNewFile);
}
catch (Exception ex)
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(false));
}
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(false));
}
else
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(true));
}
}
}
When a file is saved on an application it is a temporary url within the app's sandbox. To make this image file be publicly accessible through Apple's Photos, You'll have to use native code to do a request to add a new PHImageAsset to the photos library.
In forms you would need to access the native frameworks and therefore run native code. There are plenty of examples of doing this online if you don't know how to already. But here is an introduction if you want to run native code within a shared code framework. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Here is a sample of taking that temp file URL and saving it to Photos Framework once you can code w/ native Xamarin.iOS frameworks:
public void AddImageUrlToPhotosLibrary(string urlToSaveToPhotos)
{
PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {
//This is bound to native https://developer.apple.com/documentation/photokit/phassetchangerequest/1624060-creationrequestforasset
//Parameter is an NSURL of path to image.
PHAssetChangeRequest.FromImage(new NSUrl(urlToSaveToPhotos));
}, (completed, error) => {
if (completed)
{
if (error != null)
{
Console.WriteLine($"Failed saving image asset {error.LocalizedDescription}");
} else
{
Console.WriteLine($"Successfully saved image to photos library.");
}
}
});
}
I am not able to find the downloaded file in my apple device.
If you use a simulator, you can directly find the folder in the mac by entering the path in the
your mac --> select Finder --> Then open the Go menu --> Click Go to Folder as I described in this thread:
Where can I find the MyDocuments folder on iPhone Simulator?
If you installed the app in a real device. You can browse the file in
Xcode --> Devices and Simulators --> download container as described in this thread:
Browse the files created on a device by the iOS application I'm developing, after downloading the container, you can right click it and choose Show Package Contents. Then you can see the folders.
You can also access the file by the path in the project.
I am trying to run mobile web appium scripts in iOS Simulator .
I used the below Desired capabilities in my code .
Appium version : 1.15.0
MAC version : 10.14.6
xcode version : 11.0
Simulator version : 10.3
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability(CapabilityType.BROWSER_NAME, "safari");
caps.setCapability("platformVersion", "10.3");
caps.setCapability("deviceName", "iPhone 7");
caps.setCapability("automationName", "XCUITest");
try {
driver =new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
driver.get("https://shopping.google.com");
But i am getting a black white screen with a text as "Let's browser " and the execution gets stuck until I kill the session .
Anythoughts on this ? How to fix it
I have updated my simulator version to 12.2 and mentioned the correct name in desired capabilities , this resolved my problem
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability(CapabilityType.BROWSER_NAME, "safari");
caps.setCapability("platformVersion", "12.2");
caps.setCapability("deviceName", "iPhone 8 Plus");
caps.setCapability("automationName", "XCUITest");
try {
driver =new RemoteWebDriver(new URL(prop.getProperty("AppiumurlPort")),caps);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am working on xamarin forms. Where I am consuming the API. When I am running the app in android 5 it is working fine but If I am running 7 + it is giving the error like
Unable to resolve host "almsdev.southeastasia.cloudapp.azure.com": No address associated with hostname.
How to resolve this?
Following is the code snippet:
public async Task<HttpResponseMessage> Login(string EmailOrMobile)
{
try
{
var responseTask = await client.GetAsync(OauthBaseUrl + "OAuthSAAS/MSLogin?UserCredentials=" + EmailOrMobile);
return responseTask;
}
catch (Exception ex)
{
Crashes.TrackError(ex);
return null;
}
}
On button click I am calling above method
private async void fn_Submit_Clicked(object sender, EventArgs e)
{
var response = await _oauthService.Login(txt_credentails.Text.Trim());
}
My Base URL is
http://almsdev.southeastasia.cloudapp.azure.com:81/api/
I am using
Http client = new Http();
Since you are targeting Android 9.0(API level 28) cleartext(non-HTTPS) support is disabled by default.
To overcome this you can: either use HTTPS, or, add configs to allow http traffic.
First, in your Android Project, create a folder: xml and add the file network_security_config
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">almsdev.southeastasia.cloudapp.azure.com</domain>
</domain-config>
</network-security-config>
Then, in your Manifest.xml
<application android:label="YourAppName" android:networkSecurityConfig="#xml/network_security_config">
You can read more in the Xamarin Blog Post
Try to Add the login credentials to your Header Http Client.
I have a very simple REST query to our WebAPI back end (used by a number of applications) and it works fine under Android and Windows but in iOS it fails with an "Object reference not set to an instance of an object" error. In the code below, both moHttpClient and loUri are instantiated. I've tried wrapping the call to GetEmployeeRecord in Device.BeginInvokeOnMainThread but that doesn't help either. I have upgraded to the latest stable version of Xamarin in Visual Studio and on my Mac. Why is it working in the other OSs but not iOS?
private async void btnTest_Clicked(object sender, EventArgs e)
{
await GetEmployeeRecord();
}
private async Task GetEmployeeRecord()
{
try
{
var loUri = new Uri("https://my.website.com/mobile.webapp/api/employees?key=6c6f2c06-a444-4e54-bd77-b5f594c29910");
var loResponse = await moHttpClient.GetAsync(loUri);
if (loResponse.IsSuccessStatusCode)
{
var lcJson = await loResponse.Content.ReadAsStringAsync();
await DisplayAlert("Employee", lcJson, "OK");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
DisplayAlert("Get Employee Record", ex.Message, "OK");
});
}
}
Using a breakpoint at the GetAsync line, both moHttpClient and loUri are instantiated. However, mousing over GetAsync gives a message that GetAsync is an unknown member. How can that be?
I just checked and it seems this Unknown member occurs with Android too. But with Android it actually executes.
In order to get the http query to work for iOS I had to install the NuGet package Microsoft.Net.Http in the PCL project, which is where the code is running.