Shared preferences in mono android - xamarin.android

Hello I am new to mono android I want to use shared preferences for saving Login details in my application
someone please help me

To repeat my answer from this question...
Retrieve:
var prefs = Application.Context.GetSharedPreferences("MyApp", FileCreationMode.Private);
var somePref = prefs.GetString("PrefName", null);
Store:
var prefEditor = prefs.Edit();
prefEditor.PutString("PrefName", "Some value");
prefEditor.Commit();

Related

Google ads scripts: newVideoAd This is not implemented yet. For currently supported API

8/3/2022 13:40:32 NotImplementedError: This is not implemented yet. For currently supported API, see: https://developers.google.com/google-ads/scripts-beta/docs/reference/adsapp/adsapp
at Ha (adsapp_compiled:298:11)
at new $y (adsapp_compiled:13027:5)
at qC.newVideoAd (adsapp_compiled:15250:12)
at Object.<anonymous> (adsapp_compiled:18396:54)
var youtubeVideoId = "youtubeVideoId";
var adGroupName = "adGroupName" // name of my target video ad group
var displayUrl = "display-url.com";
var finalUrl = "https://final-url.com";
var assetOperation = AdsApp.adAssets().newYouTubeVideoAssetBuilder()
.withName(adName)
.withYouTubeVideoId(youtubeVideoId)
.build();
var videoAsset = assetOperation.getResult();
var videoAdGroup = AdsApp.videoAdGroups()
.withCondition(`Name = '${adGroupName}'`)
.withLimit(1)
.get()
.next();
var videoAdOperation = videoAdGroup.newVideoAd().inStreamAdBuilder()
.withVideo(videoAsset)
.withAdName(adName)
.withDisplayUrl(displayUrl)
.withFinalUrl(finalUrl)
.build()
.getResult();
// Code crash before next statement
if(videoAdOperation.isSuccessful()) {
var videoAd = videoAdOperation.getResult();
Logger.log("VideoAd " + videoAd.getName() + " created.");
} else {
Logger.log(videoAdOperation.getErrors());
}
Code breaks after videoAdGroup.newVideoAd().inStreamAdBuilder().
Following the google ads script docs everything should works nice.
But when I compile the script, I always get the next error:
I have just found in a Google ads scripts forum somebody who has the same problem here but no solution.
The problem is that beta mode which is active by default. Must be switched off for this action.
As a negative point, switch off Beta mode will not allow you to use javascript arrow functions, neither js classes.

Xamarin Android AWS Error getting response stream (ReadDoneAsync2): ReceiveFailure

Updated visual studio to 15.8.5 and AWS library AWSSDK.Extensions.CognitoAuthentication stopped working with error above
Amazon.AWSConfigs.AWSRegion = AWSConfigConstants.Region;
var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), FallbackRegionFactory.GetRegionEndpoint());
var userPool = new CognitoUserPool(AWSConfigConstants.PoolId, AWSConfigConstants.ClientId, provider);
var user = new CognitoUser(model.UserName, AWSConfigConstants.ClientId, userPool, provider);
authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest()
{
Password = model.Password
}).ConfigureAwait(false);
It's a bug related to mono update: https://github.com/aws/aws-sdk-net/issues/1068

Cannot store Certificate to KeyChain using SecKeyChain in Xamarin

After hours spent reading through what's available online to fix this, I decided to post my question here.
My goal is simple: Store an X509Certficate to KeyChain using Xamarin for iOS. This is a self signed certificate that I generated using BouncyCastle library.
I'm successfuly importing it, but when saving to KeyChain using SecKeyChain.Add, the result is always SecStatusCode.Paramwhich the documentation explains is missing or invalid parameter. Here's the method I use
public static bool StoreCertInKeyChain(X509Certificate2 certificate, string password)
{
var data = certificate.Export(X509ContentType.Pkcs12, password);
var options = NSMutableDictionary.FromObjectAndKey(FromObject(password), SecImportExport.Passphrase);
var statusCode = SecImportExport.ImportPkcs12(data, options, out NSDictionary[] result);
if (statusCode != SecStatusCode.Success) return false;
var certChain = result[0][SecImportExport.CertChain];
var record = new SecRecord(SecKind.Certificate)
{
Label = "MyKey",
Account = "Certificate",
ApplicationTag = "MyTag"
};
record.SetValueRef(certChain);
// Using the below code instead, produces the same result
// var cert = new SecCertificate(certChain.Handle);
// record.SetValueRef(cert);
var resultAdd = SecKeyChain.Add(record);
return resultAdd == SecStatusCode.Success;
}
Has anyone ran into this problem? I'm out of ideas what else to try. I followed the examples given on Xamarin documentation site, without success. Thank you
Answering my solution here, in case anyone else runs into the same issue. The problem was that the certificate supplied in the SecRecord wasn't an instance of SecCertificate, so using SecImportExport.ImportPkcs12 was the wrong way to do it. I ended up using SecIdentity.Import instead, which gives a reference to the certificate as well as the private key in it. The certificate and the private key need to be added to key chain separately using an identity. Here's the code that accomplishes this.
var identity = SecIdentity.Import(certificate.Export(X509ContentType.Pkcs12, password), password);
var storedCertificate = SecKeyChain.QueryAsConcreteType(new SecRecord(SecKind.Certificate) { Label = "My Cert" }, out SecStatusCode statusCode);
if (statusCode != SecStatusCode.Success)
{
var record = new SecRecord(SecKind.Certificate);
record.Label = "My Cert";
record.SetValueRef(identity.Certificate);
var result = SecKeyChain.Add(record);
SecKeyChain.AddIdentity(identity);
storedCertificate = SecKeyChain.QueryAsConcreteType(new SecRecord(SecKind.Certificate) { Label = "My Cert" }, out statusCode);
}
var storedIdentity = SecKeyChain.FindIdentity(storedCertificate as SecCertificate);
The certificate can be retrieved using the label, but to get the private key, the identity must be queried using the certificate as parameter in SecKeyChain.FindIdentity. From this point on, access to signing and decryption on the private key is available from the identity instance.

How to get iOS device token in Kony studio app

I am an iOS developer & currently working on an app in Kony studio. I have to send iOS device token on server for Push notification via a json service. Is there any way/api in kony studio to get iOS device token?
Any help or idea would be great for me.
Thanks.
Here is what I am using in my Kony Studio project:
subscriptionArguments.deviceId = kony.os.deviceInfo().identifierForVendor;
We are using Kony visualizer 7.x. And use the code as below to register the device for push notification.
try {
setStatus("Getting device info.."); //Own function
messagingClient = client.getMessagingService();
var osType = "";
if(kony.os.deviceInfo().name=="iphone" || kony.os.deviceInfo().name=="iPhone"){
osType = "iphone";
}else{
osType = "androidgcm";
}
var deviceInfo = kony.os.deviceInfo();
var deviceId = deviceInfo.deviceid;
var userId = emailId;
messagingClient.register(osType,deviceId,deviceRegID,userId,pushSubscriptionSuccessCallback,pushSubscriptionErrorCallback);
setStatus("Subscribing..");
}catch (e) {
kony.print("Error while subscribing the device " + e);
}
Hope this helps!
var deviceInfo = kony.os.deviceInfo();
var deviceID=deviceInfo.deviceid;
Above Code will give device ID for anddroid, but for IOS it will give 02:00:00:00:00:00, which is not helpful.
You can do it using below code for IOS.
var deviceID= deviceInfo.identifierForVendor;----for and above 6.0 and
var deviceID= deviceInfo.customdeviceid;----- below 6.0
Reference: http://docs.kony.com/5_6_PDFs/Kony_API_Reference_Guide.pdf

Phonegap Calendar plugin is asking for calendarName in findAllEventsInNamedCalendar method

I am using calendar plugin to fetch all the events from iOS native calendar.
https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin
I am trying to use the below method for that.
var calendarName = "iCal";
window.plugins.calendar.findAllEventsInNamedCalendar(calendarName,success,error);
When I am running the application, and trying to fetch all the events, it is showing the below error.
"Error: could not find calendar."
$("#create").click(function(){
window.plugins.calendar.createEvent(title,location1,notes,startDate,endDate,success,error);
});
$("#find").click(function(){
window.plugins.calendar.findEvent(title,location1,notes,startDate,endDate,success,error);
});
$("#deleteAll").click(function(){
window.plugins.calendar.deleteEvent(title,location1,notes,startDate,endDate,success,error);
});
Create events, find events and Delete is working.
Can any one help to find out what should be the value of "calendarName" variable to find the value from iOS native database ?
you are just running full code which is given to github right
first you have to create calendar then you can find it. in below sequence once calendar is created then in second it will be deleted too.
// prep some variables
var startDate = new Date("September 24, 2013 13:00:00");
var endDate = new Date("September 24, 2013 14:30:00");
var title = "My nice event";
var location = "Home";
var notes = "Some notes about this event.";
var success = function(message) { alert("Success: " + JSON.stringify(message)); };
var error = function(message) { alert("Error: " + message); };
var calendarName = "iCal";
// create a calendar (iOS only for now)
window.plugins.calendar.createCalendar(calendarName,success,error);
// create in a named calendar (iOS only for now)
window.plugins.calendar.createEventInNamedCalendar(title,location,notes,startDate,endDate,calendarName,success,error);
Now you can check below events
// find (iOS only for now)
window.plugins.calendar.findEvent(title,location,notes,startDate,endDate,success,error);
// find all events in a named calendar (iOS only for now)
window.plugins.calendar.findAllEventsInNamedCalendar(calendarName,success,error);
the PhoneGap 2.x version does not support the named calendar. Maybe you are using the 2.x version of the plugin with the 3.x readme?
Please refer to the 2.x readme: https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/tree/pre-3.0

Resources