Send data from Share Extension to Xamatin.Forms app - xamarin.forms

I work on Share Extension. And it only has a sample project (following link) and a general extension documentation.
Basic project:
Extension documentation:
When I click share with my app on iphone (for example on photos), I want to send this file to my app and upload it remote server. But I couldn't find anyway to send object from share extension. I looked up and probably I need to use "NSUserDefaults" and I tried to use it that:
I did necessary settings (creating group id, app id etc) on my apple developer account.
I did necessary settings on my project Entitlements.plist
I try to send on ShareViewController - DidSelectPost method in the my project's share extension as below:
var default = new NSUserDefaults ("group.com.myapp.AppName", NSUserDefaultsType.SuiteName);
default.SetString ("Test content", "TestKey");
default.Synchronize ();
4)I try to receive string data on my main project's AppDelegate as below:
var default = new NSUserDefaults ("group.com.myapp.AppName", NSUserDefaultsType.SuiteName);
var key = default.StringForKey ("TestKey");
string value = key;
But I couldn't do it. And I saw someone did this with OpenUrl function. I tried this and this didn't work.
I started mobile programming with Xamarin forms and I don't know enough native iOS programming (I only learn with Xamarin). I think share extension has insufficient documentation.

Related

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.

Get role of current user in Sharepoint Online site using Microsoft Graph

I am building a .net core web app in which i use AzureAD auth and Microsoft Graph to get data from a sharepoint online site.
I need to get the groups of the current user.
I tried to use graphClient.Me.MemberOf.Request().GetAsync();
I think i'm getting the role of the user in the Azure directory.
But i want the role of the current user for a specific sharepoint online site.
Is that possible to get this information and how ?
I don't find a working way to get this using Microsoft Graph.
EDIT:
As Microsoft Graph doesn't allow to get that data.
I tried to call the following Sharepoint Online API endpoint :
https://{name}.sharepoint.com/sites/{name}/_api/web/currentUser?$select=Groups/Title&$expand=Groups
Using this api endpoint i can see all the roles of the current user in my browser.
But i don't find how to call it from my .net core web app.
Tried the following :
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Content-types", "application/json;odata=verbose");
var response = await client.GetAsync("https://{name}.sharepoint.com/sites/{name}/_api/web/currentUser?$select=Groups/Title&$expand=Groups");
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
}
But that give me a 403 response.
EDIT 2 :
I am currently trying to use CSOM to get this informations(TCUE.NetCore.SharepointOnline.CSOM.16.1.8029.1200.)
But i don't find a way to get TokenHelper.cs.
var token = TokenHelper.GetAppOnlyAccessToken(SharePointPrincipalId, webUri.Authority, null).AccessToken;
var ctx = TokenHelper.GetClientContextWithAccessToken(webUri.ToString(), token);
I tried to add "AppForSharePointOnlineWebToolkit" and it did not add the needed files in the project.
How can i get the TokenHelper.cs file ?
Thanks for any help.
Tristan
To execute CSOM code in .net core, do below settings.
We can install the package as below.
Install-Package TTCUE.NetCore.SharepointOnline.CSOM.16.1.8029.1200 -Version 16.1.8029.1200
More information is here: TTCUE.NetCore.SharepointOnline.CSOM.16.1.8029.1200
Or use the following solution from GitHub: NetCore.CSOM
Or follow the steps below.
1.Create a .NET Core console app.
2.Add the references: Microsoft.SharePoint.Client.Portable.dll, Microsoft.SharePoint.Client.Runtime.Portable.dll, and Microsoft.SharePoint.Client.Runtime.Windows.dll.
Note: If the project has references to Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll, please remove them.
These references can be accessed by installing CSOM library into another project, and then navigating to installed nuget packages in the file directory: c:\Users\user.nuget\packages\microsoft.sharepointonline.csom(version)\lib\netcore45
3.Add the code below to the .NET Core 2.0 console application:
Get current user role:
To get the current user role, you can use Web.GetUserEffectivePermissions method.
Ex:
ClientResult<BasePermissions> permission= web.GetUserEffectivePermissions(name);
context.ExecuteQuery();
var res = permission.Value;
Refer below link to get clientcontext using access token: https://www.sharepointpals.com/post/how-to-get-the-client-context-using-app-access-token-by-passing-client-id-and-client-secret-id-using-csom-in-sharepoint-office-365/
No. Microsoft Graph doesn't expose an endpoint that allows you to get the information of SharePoint Group and its members.
If you has this requirement, you could vote this idea on Microsoft Graph UserVoice.

How do you test Firebase Dynamic Links in Unity?

Based on the Firebase Unity documentation, you only need to add Firebase Dynamic Links SDK and then listen for incoming links like this in order to capture Dynamic links:
void Start()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
// Display the dynamic link received by the application.
void OnDynamicLink(object sender, EventArgs args)
{
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
The dynamic link I have previously generated, correctly redirects me to the Google play store where my app exists. When I click on "open" from the play store, my app opens on the device but dynamic link information is not passed at all.
Do I need to create a new alpha version of my app to test this on Play Store?
Some people in Stackoverflow mentioned about Alpha version, but those people don't have an app released, whereas I do.
Also, is there way to test this in Unity editor?
I still need to write the code to parse it and it's kind of ridiculous to blindly code this.
If you are still testing and don't want to release a version with Dynamic Links to production, you can release your build which has Dynamic Links to a beta release so you can be sure it's working as expected.
Otherwise, releasing to production also will work.
The build you are installing from play store needs to have the Dynamic Links library and also the codes anyway.

How to Store user login credential in Xamarin.Form

I want to store the username and password of users locally. i have searched a lot can't find a working solution for Xamarin.forms.I have seen this official site that recommend to use Xamarin.Auth to store in keychain but the tutorial in on platforms specific which i dont know how to convert to Xamarin.Forms.
A little bit help on how to make this to work in Xamarin.Form is very much appreciate.
I have been using the SecureStorage plugin which saves these kinds of settings in the platforms secure storage from the shared code.
There are a couple of things good to know.
iOS
On the Simulator you could run into an issue where values do not get saved. To overcome this open the Entitlements.plist file and make sure that "Enable Keychain Access Groups" is checked. Also ensure that in Project->Options->iOS Bundle Signing, the Entitlements.plist is selected in Custom Entitlements for iPhoneSimulator platform.
Android
You have to set a password when initialising, like this:
SecureStorageImplementation.StoragePassword = "Your Password";
This will be used to encrypt te settings. Make sure you keep it secret and do not change it.
Windows
Same thing as Android, but now call WinSecureStorageBase.StoragePassword = "Your password";
If you have done this, you can now save any setting your like with:
CrossSecureStorage.Current.SetValue(“SessionToken”, “1234567890”);
Which can then be retrieved like this:
var sessionToken = CrossSecureStorage.Current.GetValue (“SessionToken”);
There are some more calls to delete a key and see if a key is present. Don't forget to install the NuGet package on both your shared code as well as your platform projects.
You can check on this link for how to use Xamarin.Auth in Xamarin.Forms.
One more option i would consider is using Akavache which can be used to store the data with same level of security & how to integrate it in Xamarin.Forms check on this link

Firefox webapp file input

I'm developing a webapp for firefox aurora (android). And i have an file input.
But when users click on the input they can't choose files from sdcard or filesystem only pictures, music or videos.
I search at MOZILLA DEVELOPER NETWORK, but couldn't find anything helpful.
In my manifest.webbapp i have device-storage permission:
"permissions": {
"device-storage:sdcard":{ "access": "readonly" }
},
I assume you are currently simply using the markup ?
The device-storage:sdcard is for a very different set of use cases really. And we don't have that implemented on Firefox for Android yet.
The list of applications being shown is just the set of applications that we're getting from the Android Intents system. I would imagine that if the user has some sort of filebrowser app installed it might respond to that intent and it'd pop up there.
But of course that's not something you can rely on in your app.
I'm honestly somewhat surprised that there's no default applications on android that provide that functionality, but I guess that's how it is. Or does someone know of a way to also get a filepicker intent that we can hook up to?
Medium term you will be able to use the DeviceStorage API. This will give you direct JS access to the sdcard which will allow you to build your own UI for choosing a file from the SD card. But that extra power comes with quite a few downsides. It's a privileged API which means that you'll have to write the app as a packaged app and you have to use CSP. And you'll have to go through the Firefox marketplace review process (all privileged apps have to go through code review).
So it's a pretty distant second choice.
Other than that there aren't any solutions. The best would of course be if there was a way we could plopp up an Android file picker, but I'm not sure if that's doable. And it's definitely not implemented yet.
According to the source code, this permission is only granted to apps that are packaged and privileged, the latter also means the app has to be signed by the Marketplace.
You can find more about packaged apps and privileged app types here:
https://developer.mozilla.org/en-US/docs/Apps/Packaged_apps
Just install an Android file manager app (https://play.google.com/store/search?q=file+manager&c=apps) and you will be able to select files from the SD card. There is no need for specific rights because this is handled automatically by the standard file input.
Accessing the SD Card can only be achieved through a privileged or certified app. Currently to my knowledge, there is no integration the system menus as you are hoping would be the case. Personally, I'm hoping that this will change.
API Documentation: https://developer.mozilla.org/en-US/docs/WebAPI/Device_Storage
You could create your own menu that mimics the the system one; in this way the user gets a seamless experience and they don't know the difference. It would require a little boilerplate though it's not insurmountable levels of boilerplate.
A quick snippet for browsing/enumerating all photos on the the SDCard:
var storage = navigator.getDeviceStorage("sdcard");
sdcard.browse = function () {
var pics = navigator.getDeviceStorage('pictures');
// Let's browse all the images available
var cursor = pics.enumerate();
cursor.onsuccess = function () {
var file = this.result;
alert("File found: " + file.name);
// Once we found a file we check if there are other results
if (!this.done) {
// Then we move to the next result, which call the cursor
// success with the next file as result.
this.continue();
}
}
cursor.onerror = function () {
alert("No files found: " + this.error);
}
};
If you would like some more details for reading, writing, and caulating available storage, I'm currently working on a little wrapper library in my spare time to work with the SDCard more easily (and handle some callbacks to integrate better with other code) in my spare time and can probably help you out.

Resources