how get key/value from nsuserdefaults .plist configuration file Xamarin forms - xamarin.forms

I am working as a Xamarin forms iOS enterprise app.
We pushed config.plist (Some key-value pair) file to a real device using Mobileiron/airwatch MDM/EMM(Services). Then we deploy the Apps on iPads using MobileIron. When the app starts, the app gets Url/ credentials from config.plist that pushed by MDM.
after googling I found config.plist stored in device which in NSUserDefaults​
But I am don't know is the .plist stored in NSUserDefaults with apps bundle id or something else.
Please anybody has the same issue before writing to me how I have to implements or getting value from .plist

I think you will find the details from your question on page 69-70 of Apple's MDM-Protocol-Reference. The MDM server deploys these settings using a dictionary that contains an array of bundle ids, with the settings for each app within their key. Because of how sandboxing works, your app just has to retrieve the com.apple.configuration.managed key to get its settings.
A great resource is https://www.appconfig.org/ios/

Related

Resource does not contain a definition for Raw while migrating resources in a MAUI app and how to load them

While migrating a Xamarin forms app, I find my self having this Android specific code that try to load my sound resource with a resource id
MediaPlayer.Create(Android.App.Application.Context, Resource.Raw.beepok);
I see that maui is bunding everything on Resources\Raw\** as MauiAsset
How i can still get the resource id?
It seem that AndroidResource still works, it seem that i was hit a build cache of sort, after clean and restarting vs the resource is available

Setup Firebase Remote Config

I want to use Remote Config in a application Xamarin.Forms.
I use a blog - Firebase Remote Config in Xamarin Forms
I have a question about the section: Setup Firebase Remote Config.
Quote
We can setup Firebase Remote Config through the Firebase portal https://console.firebase.google.com/project/Your-Firebase-Project/config and it is an easy process because the portal GUI is nice and friendly. To do it, we add a new parameter key and the default value and of course it can be a json (the GUI has a tool to validate the format of the json content). In the example case the key will be Features and the default value a json:
{
"ShowPlayerDetail": false
}
In this case, we setup a key called ShowPlayerDetail to show or not the player detail.
Question:
Where is the JSON file referred to in this section?
Note.
I am currently in a project.
Update-1
Update-2
Update-3
Update-4
Update-5
I have completed the following steps.
Did I do the right thing?
Do my actions correspond to what is described in the blog?
Or do I need to perform Publish changes? (see Pic-4. Result)
Pic-1
Pic-2
Pic-3
Pic-4. Result
You're using an existing Firebase project but there are no apps in your project, please see the Update-4 screenshot .
You could click the iOS or Android icon to add app to your Firebase project, and make sure the Apple bundle ID matches the Bundle identifier in info.plist of your Xamarin.iOS project, the Android package name matches the packagename in AndroidManifest.xml of your Xamarin.Android project. After registering the app, you can download the google-services.json file for Android and the GoogleService-Info.plist file for iOS.

How to use the Storage Attach Service for public storage access instead of private storage access?

Problem Summary
My app (in development), when run on the desktop, can both:
Write to & read from private storage
Write to & read from public storage.
However, when run on Android, only private storage is accessible.
How To Replicate The Issue
Instead of sharing excerpts of my project's codebase, let me refer to another codebase we share and have - the gluon-connect-file-provider project in Gluon Samples. The sample apps only demonstrate private storage usage. None demonstrate public storage usage, so in the gluon-connect-file-provider project, you can make the following change in com.gluonhq.samples.connect.file.Main.java:
Before
static {
ROOT_DIR = Services.get(StorageService.class)
.flatMap(StorageService:getPrivateStorage)
.orElseThrow(() -> new RuntimeException("Error retrieving private storage"));
}
After
static {
ROOT_DIR = Services.get(StorageService.class)
.flatMap(s -> s.getPublicStorage("Gluon"))
.orElseThrow(() -> new RuntimeException("Error retrieving public storage"));
ROOT_DIR.mkdir();
}
When starting the app on the Desktop after this change, you can first observe the directory ~/Gluon being created on your machine. Then, as you toggle the checkbox on/off in the app's Object Viewer screen, you can also confirm the underlying JSON file ~/Gluon/user.json is being updated. So, therefore, we can agree public storage works.
However, when deployed to Android, we can see file-permission related failures in the scrolling terminal during mvn -Pandroid gluonfx:nativerun. First, the Gluon directory fails to be created at startup and, consequently later, attempts to write the user.json file occur.
I thought the soluton was to define in the project the file src/android/AndroidManifest.xml. The default found at target/gluonfx/aarch64-android/gensrc/android/AndroidManifest.xml does not include the following permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
So, I copied the generated AndroidManifest.xml file to src/android, including these entries to it. Even though the Android Settings shows me my app has Storage Permission, this still didn't resolve the problem.
Note - when preparing this post asking for your help, I noticed that, without also provisioning src/android/AndroidManifest.xml file with EXTERNAL READ/WRITE permissions for the gluon-connect-file-provider, the Android device already showed the deployed app had Storage Permission enabled.
I used two different Android devices to test with.
Pixel XL running Android version 10.
Samsung S9 running Android version 10.
I tested with the latest GluonHQ Attach dependency 4.0.13 and also with the oldest I found available, 4.0.7.
Is there something more that must be done for the Storage Attach Service to allow public storage access on Android? Please tell me how else to modify the gluon-connect-file-provider app to make it so, thank you.
Resolution
Update to Gluon Attach 4.0.14.
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>storage</artifactId>
<version>4.0.14</version>
</dependency>
With this update, Storage Service will allow you to access pre-existing Android folders, like "Documents" for example. Or, as seen in this post's code excerpt above, you can define your own new directory like "Gluon", or naming the folder after your own App.
Extra
Another cascading result of this Attach update is, in addition to Storage Service, file sharing via the Share Service is now available on Android. Its JavaDoc states Storage Service as a requirement to use Share Service. Below is a quote from its documentation:
Note that on Android, the file has to be located in a public folder
(see StorageService#getPublicStorage), or sharing it won't be allowed.

SQLite Database Versioning and Xamarin Config String

I have an Xamarin Android (and maybe someday iOS) app that utilizes a rather sizable SQLite database (20MB+). I am somewhat new to mobile app development and definitely to Xamarin. I need to control database versioning. This is a best-practice question.
Edit/Clarification: Some of the data is app/user created or maintained. Some of the data is generated via a 3rd party and is read only, in 2nd and 3rd normal form. That data must be updated with version release. Also, the user will purchase some of these data sets in-app.
My Plan:
Everytime the app opens - OnStart (), I will validate the version of the database that is supposed to exist via a configuration string against a table value in the SQLite database with version info. If the versions don't match, the database file will be copied from the APK/assets to a local folder on the device, overwriting the existing file. I definitely don't want this to happen everytime the app opens for many reasons.
3-part question:
First, is this solution a solid approach without major road blocks? Where in Xamarin (or Android project) is best to store the database version string? And finally, is there a 3rd party library (preferably nuget) which already handles database versioning? I cannot find anything like that for .NET / Xamarin. Only some Java libraries which are more Android specific.

How to update Watch app with updates in core data?

We support iOS 7, so I am not using a framework. The app is mostly objective-c, and the watchkit extension mostly in swift. The AppDelegate manages the Core Data objects.
Our app allows the user to choose a configuration to change what they see. They can switch to a different configuration. When they switch, we remove most everything from NSDefaults and we remove the sqlite database and recreate it. When they switch, its basically starting over.
On the watch side, I have a swift class that has a lazy loaded Singleton of an object that manages the core data objects. But when the app resets its data, how can we report this out to the watch extension? I am guessing that I have to reset the managed object context that the extension created.
You can use MMWormHole to send messages from your iPhone app to your WatchKit extension. In your WatchKit extension you can set the stalenessInterval for your Core Data database to something really short and you will also probably want to refresh your NSManagedObjects.

Resources