Disable default alert when Bluetooth is Turned OFF in iOS - xamarin

I have integrated SerialIO RFID SDK and using Bluetooth LE Plugin to check Bluetooth Status in my Xamarin.iOS app.
Each time when I launch the app, it keeps showing me the alert as soon as any of the code from above SDK or plugin is invoked. I don't want to show this alert. Instead, I want to notify user about this, in some other way.
I found this way to disable this alert, but Where and How to
write this in Xamarin, is my Question.
I searched a lot for Xamarin Specific solution and didn't find any.
I tried following in AppDelegate.cs but none of them worked. May be I am not sure how to write this.
// Way : 1
var cbCentralInitOptions = new CBCentralInitOptions();
cbCentralInitOptions.ShowPowerAlert = false;
var cbCentralManager = new CBCentralManager(this, null, cbCentralInitOptions);
// Way : 2
//NSDictionary options = new NSDictionary();
//options.SetValueForKey(NSNumber.FromNUInt(0), CBCentralManager.OptionShowPowerAlertKey);
//var cbCentralManager = new CBCentralManager(this, null, options);
Please help me to get this default alert suppressed. Thanks.

Related

Teams: How to open Task Module from Adaptive Card in desktop app

I am sending an adaptive card to teams with the bot framework. That is working fine. The card should contain an action that opens a task module like explained here.
My code for the card looks like this:
AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 3))
{
Body = new List<AdaptiveElement>() {
new AdaptiveTextBlock() {
Wrap = true,
Text = "test",
IsSubtle = false,
Size = AdaptiveTextSize.Large,
Weight = AdaptiveTextWeight.Bolder
}
},
Actions = new List<AdaptiveAction>() {
new AdaptiveSubmitAction()
{
Title = "In Teams",
DataJson = $"{{\"msteams\":{{\"type\":\"task/fetch\"}},\"Url\":\"{url}\",\"Title\": \"{title}\"}}"
}
}
};
The card is showing in teams, but the button is not working in the desktop client. It is just showing this message in red:
Something went wrong. Please try again.
In the web version the task module is just opening fine. Do I have to change something for the desktop version of teams? Tried to change my code a bit like in this example but that isn't working either.
Update:
So I tried the example and it did work one time. After that I had the same error message and no task module is showing. But when I pop out the App in a new window, everything is working fine. So it looks to me like a bug in teams.
I had the same problem with the message “Something went wrong. Try again.", when called Task Module from adaptive card. I installed the bot through a local upload of the manifest, but then I found out that it was also added to the list of applications for our organization, and apparently there was some kind of collision between them. After I uninstalled the application from my desktop Teams and installed it from the application pool - the error disappeared.
This might relate to how the platform is reading your json - the "" characters for example might not be handled properly on the desktop. To solve this, rather leave the json conversion up to the platform and, for your example in C#, create a strong type instead. The example you link to does exactly that - see this line:
new TaskModuleAction(cardType.ButtonTitle, new CardTaskFetchValue<string>() { Data = cardType.Id }
inside https://github.com/microsoft/BotBuilder-Samples/blob/448c5535cb6d6be8d7a61f78ef1902b55c1f0edb/samples/csharp_dotnetcore/54.teams-task-module/Bots/TeamsTaskModuleBot.cs, which is referencing this class: https://github.com/microsoft/BotBuilder-Samples/blob/901bc140f5aa300fbfa852e64afd7c65fceebff9/samples/csharp_dotnetcore/54.teams-task-module/Models/AdaptiveCardTaskFetchValue.cs

How do I deal with a possible exception in a Xamarin Forms application deployed to iOS or Android?

I have a finished application which I would like to make available to run on the iOS and Android platforms.  I have tested the application as much as possible and it works without problem.  But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}

Push Notification to specific devices on xamarin forms android/ios

I have successfully set up push notification using firebase and linked it up Azure notification hub using this guide from the Microsoft docs:
https://learn.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-push-notifications-android-gcm
However I am now trying to push notification to specific devices using tags. There isn't currently a xamarin c# document. I have done some research around the area and found people solving what seems to be the same problem using dependency injection (which feels a little complex?). I have also found these two questions/answers:
How to push notification to specific users in Xamarin.Forms Android?
https://forums.xamarin.com/discussion/85935/how-to-push-notification-to-specific-users-in-xamarin-forms-android
Both of which point to the method "OnRegistered" which i don't seem to have? i've had another look through the documentation I followed to set up notifications in the first place and I seem to have followed it correctly?
I have the following code for android:
private void SendRegistrationToServer(string token)
{
// Register with Notification Hubs
hub = new NotificationHub(ApplicationConstants.NotificationHubName,
ApplicationConstants.ListenConnectionString, this);
var tags = new List<string>() { };
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
}
I can obviously set the tags manually there, however how do i 'call' this Method again if the tags need to be changed?
So bottom line, my question is how do i set up push notification to specific devices on xamarin.forms android/ios?
Thanks.

App Center in-app updates not showing up in Xamarin Android app

I'm attempting to configure AppCenter.Distribute for in-app updates within my Xamarin Android app. Here is the very basic setup code, which I have in my main launcher activity's OnCreate method (AFTER the base.OnCreate call):
AppCenter.Start (Resources.GetString (Resource.String.appcenter_app_secret), typeof (Analytics), typeof (Crashes), typeof (Distribute));
I was able to get the in-app updates to supposedly initialize. When I first install and open the app, it shows a browser window for one second that says "In-app updates enabled! Returning to app in 1...", then it redirects back to my app. Unfortunately, when I then bump the version name and code and distribute a new build, I don't get a dialog within the app prompting me to update to the new version.
I even tried handling the Distribute.ReleaseAvailable action and showing a custom dialog, and that action isn't invoked either:
Distribute.ReleaseAvailable = OnReleaseAvailable;// Called before AppCenter.Start
private bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
// Show custom dialog.
Droid.ApplicationContext.Activity.CustomDialogBuilder().Show(new NotificationArgs
{
Title = "New update available!",
Message = "A new version of RPR Mobile, {0} ({1}) is available. Release notes: {2}"
.WithFormat(releaseDetails.ShortVersion, releaseDetails.Version, releaseDetails.ReleaseNotes),
PositiveButtonText = "Update",
PositiveAction = () =>
{
// Notify SDK that user selected to update...
Distribute.NotifyUpdateAction(UpdateAction.Update);
},
HideNegativeButton = releaseDetails.MandatoryUpdate,
NegativeButtonText = "Postpone Update",
NegativeAction = () =>
{
// Notify SDK that user selected to postpone (for 1 day)...
// Note that this method call is ignored by the SDK if the update is mandatory.
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});
// Return true if you are using your own dialog, false otherwise.
return true;
}
I'm wondering what I'm missing. Some questions that may or may not be relevant...
Does it matter whether the AppCenter.Start code executes before or after the base.OnCreate call?
Does it matter whether the activity that AppCenter.Start is called from is running or finished? Because in our case, the main launcher is just a splash screen that closes after a couple seconds.
Is the App Center SDK supposed to poll every few seconds for an update? Or does it check only when opening and closing activities?
It turns out that you have to close and relaunch your app for it to check for new updates. The documentation could be more clear on this...

Open Native iOS app from Xamarin.Forms

I have an native iOS sample app installed in my iPad and also my sample xamarin.Forms App installed. I want to open native iOS app from Xamarin.forms when clicked on button. I have set URL schema in my native iOS app in info.plist.
How do I open native app from xamarin.forms on click of a button. I already tried
var request = Device.OnPlatform(
string.Format("native app url"),
string.Format("native app url"),
string.Format("native app url"));
Device.OpenUri(new Uri(request));
but its not working.
It's basically how you are doing it.
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Device.OpenUri(new Uri(request));
Be aware that each platform have some requirements in the way to url is configured and parameters are sent.
Let say to get the maps app open in each platform you would use these urls schemes:
// iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
var iOSUrl = string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc);
var androidUrl = string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name);
var winPhoneUrl = $"bingmaps:?cp={loc}&q={name}";
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Also you cannot open any arbitrary app unless you know its Url scheme.
Anyway, if the Device.OpenUri() doesn't fulfill your requirements you are good to create your own implementations using the native APIs.
Please go through the below link and attached photo
Link:-launch-an-app-from-within-another-iphone
I am using below code in xamarin forms
NSUrl request = new NSUrl("Camera://");
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(request.ToString()));
if (!canOpen)
{ Task.FromResult(false); }
else
{
Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(request.ToString())));
}

Resources