11 Xamarin iOS Applications
If you use the Xamarin platform to develop iOS apps, you can use the SDK that Oracle Mobile Cloud Service (MCS) provides for Xamarin iOS apps. This SDK simplifies authentication with MCS and provides native wrapper classes for MCS platform APIs.
Getting the SDK for Xamarin iOS
To get the MCS client SDK for Xamarin iOS, go to the Oracle Technology Network’s MCS download page.
To use this SDK, you should have the following software on your system:
-
Microsoft Visual Studio, with support for Xamarin development.
-
Xcode 9.1 or later and iphoneos 11.0.
See http://www.oracle.com/technetwork/java/javase/downloads/index.html for JDK downloads.
Adding the SDK to a Xamarin iOS Project
-
If you haven’t already done so, extract the contents from the SDK zip.
-
In Visual Studio, create a Visual C# iOS app.
-
Add the SDK's DLL file to your app by right-clicking the project's References node and selecting Edit References, clicking the .NET Assembly tab, and then browsing to the
IOS.dll
file in the extracted SDK zip. -
Add the configuration file to the app by right-clicking the project's root node and selecting Add > Add Files and then navigating to the SDK's
OMC.plist
file. -
Select the node for
OMC.plist
so that it's properties are displayed in the Properties pane. Then make sure that the Build Action property is set toBundleResource
. -
Add the
SynchStore.momd
folder to the app by right-clicking the project's root node and selecting Add > Add Existing Folder and then navigating to the SDK'sSynchStore
folder. -
For all of the files in the
SynchStore.momd
folder, make sure that the Build Action property is set toBundleResource
. -
Open
OMC.plist
and fill in the environment details for the mobile backend that the app will be using. See Configuring SDK Properties for Xamarin iOS.
Configuring SDK Properties for Xamarin iOS
To use the SDK in a Xamarin iOS project, you need to add the OMC.plist
configuration file to the app and fill it in with environment details for your mobile backend. In turn, the SDK classes use this information to access the mobile backend and construct HTTP headers for REST calls made to APIs.
You package the configuration file in the root of your app’s main bundle.
Here’s an example of the contents of the OMC.plist
file. Pay careful attention to the hierarchy of elements.
Here’s the source code for the same example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
<plist version="1.0">
<dict>
<key>mobileBackends</key>
<dict>
<key>FixItFast_Customer</key>
<dict>
<key>default</key>
<true/>
<key>baseURL</key>
<string>https://fif.cloud.oracle.com</string>
<key>appKey</key>
<string>ebfbc8ea-9173-442b-8a5e-2fae63c64422</string>
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>OAuth</string>
<key>OAuth</key>
<dict>
<key>tokenEndpoint</key>
<string>https://oam.oracle.com/oam/oauth2/tokens</string>
<key>clientID</key>
<string>ddb7ff5a-0d86-4b4a-8164-ddad03734249</string>
<key>clientSecret</key>
<string>pFmzazXzNTBNVDyraQs7</string>
</dict>
</dict>
</dict>
</dict>
<key>logLevel</key>
<string>debug</string>
</dict>
</plist>
Here are the key entries in the OMC.plist
file. You can obtain the necessary environment details from the Settings and Clients pages of the mobile backend.
-
mobileBackends
— a dictionary entry containing a nested dictionary for your mobile backend such asFixItFast_Customer
. (When you callOMCMobileBackend
in an app, you need to supply the value of that entry as a parameter toOMCMobileBackendManager
.) That entry, in turn, contains entries forappKey
,baseURL
,authenticationType
,mobileBackendID
,anonymousKey
, and, optionally,networkConnectionTimeout
. See the example below. -
baseURL
— The URL your application uses to connect to its mobile backend. -
appKey
— The application key, which is a unique string assigned to your app when you register it as a client in MCS. See Registering an App as a Client in MCS. If you have not registered the app as a client in MCS, assign a placeholder value for this entry. -
authorization
— Use this key to define the type of authentication the app will be using and specify the required credentials. The contents of theauthorization
key depend on the type of authentication.-
authenticationType
— Defines the type of authentication mechanism being used in your mobile application. Possible values areOAuth
(for OAuth Consumer),basic
(for HTTP Basic),SSO
,SSOTokenExchange
andFacebook
. Include a dictionary for each supported authentication type with the required credentials as explained in the sections that follow.
-
networkConnectionTimeout
— (Optional) The network timeout for API calls, in seconds. Should you need to do any network performance tuning, you can add this property, though you should use it with care. Keep in mind that app responsiveness issues might be better addressed in the app design itself. The default timeout is 60 seconds.-
logLevel
— Determines how much SDK logging is displayed in the app’s console. The default value iserror
. Other possible values (in increasing level of detail) arewarning
,info
, anddebug
. It is also possible to set the value tonone
. -
logHTTPRequestBody
— When set totrue
, the SDK will also log the HTTP and HTTPS headers and body in the requests to MCS. -
logHTTPResponseBody
— When set totrue
, the SDK will also log the HTTP and HTTPS headers and body in responses from MCS. -
offlineAuthenticationEnabled
— If set totrue
, offline login will be allowed.
The contents and sub-elements of the authorization
dictionary depend on what kind of authentication the app will be using.
OAuth Consumer
authenticationType
property to OAuth
and fill in the OAuth credentials provided by the mobile backend.
-
tokenEndpoint
— The URL of the OAuth server your application goes to, to get its authentication token. -
clientID
— The unique client identifier assigned to all applications when they’re first created in your mobile backend. -
clientSecret
— The unique secret string assigned to all applications when they’re first created in your mobile backend.
The resulting authorization
property might look something like this:
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>oauth</string>
<key>OAuth</key>
<dict>
<key>tokenEndpoint</key>
<string>https://oam.oracle.com/oam/oauth2/tokens</string>
<key>clientID</key>
<string>ddb7ff5a-0d86-4b4a-8164-ddad03734249</string>
<key>clientSecret</key>
<string>pFmzazXzNTBNVDyraQs7</string>
</dict>
</dict>
SSO
For SSO, set the value of the authenticationType
property to SSO
and fill in the OAuth credentials provided by the mobile backend. (For tokenEndpoint
, you use the mobile backend’s OAuth token endpoint.)
The resulting authorization
property might look something like this:
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>SSO</string>
<key>SSO</key>
<dict>
<key>tokenEndpoint</key>
<string>https://oam-server.oracle.com/oam/oauth2/tokens</string>
<key>clientID</key>
<string>ddb7ff5a-0d86-4b4a-8164-ddad03734249</string>
<key>clientSecret</key>
<string>pFmzazXzNTBNVDyraQs7</string>
</dict>
</dict>
SSO with a Third-Party Token
For SSO with a third-party token, set authenticationType
to SSOTokenExchange
and fill in the appropriate credentials.
The resulting authorization
property might look something like this:
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>SSOTokenExchange</string>
<key>SSOTokenExchange</key>
<dict>
<key>mobileBackendID</key>
<string>ddb7ff5a-0d86-4b4a-8164-ddad03734249</string>
<key>anonymousKey</key>
<string>UFJJTUVfREVDRVBUSUNPTl9NT0JJTEVfQU5PTllNT1VTX0FQUElEOnZrZWJxUmwuamEwbTdu</string>
</dict>
</dict>
HTTP Basic
authenticationType
property to basic
and fill in the HTTP Basic credentials provided by the mobile backend.
-
mobileBackendID
— The unique identifier assigned to a specific mobile backend. It gets passed in an HTTP header in every REST call made from your application to MCS, to connect it to the correct mobile backend. When calling platform APIs, the SDK handles the construction of themobileBackendID
header for you. -
anonymousKey
— When using HTTP Basic authentication, a unique string that allows your app to access APIs that don’t require login. In this scenario, the anonymous key is passed to MCS instead of an encoded user name and password combination.
The resulting authorization
property might look something like this:
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>Basic</string>
<key>Basic</key>
<dict>
<key>anonymousKey</key>
<string>UFJJTUVfREVDRVBUSUNPTl9NT0JJTEVfQU5PTllNT1VTX0FQUElEOml6LmQxdTlCaWFrd2Nz</string>
<key>mobileBackendID</key>
<string>4fb9cabd-d0e2-40f8-87b5-d2d44cdd7c68</string>
</dict>
</dict>
For Facebook, set the value of the authenticationType
property to Facebook
and fill in the HTTP Basic auth credentials provided by the mobile backend plus the facebookAppID
.
The resulting authorization
property might look something like this:
<key>authorization</key>
<dict>
<key>authenticationType</key>
<string>Facebook</string>
<key>Facebook</key>
<dict>
<key>mobileBackendID</key>
<string>11d1fc49-7574-4b24-82f3-74a3720ce154</string>
<key>anonymousKey</key>
<string>UFJJTUVfREVDRVBUSUNPTl9NT0JJTEVfQU5PTllNT1VTX0FQUElEOml6LmQxdTlCaWFrd2Nz</string>
<key>facebookAppID</key>
<string>154198719279</string>
</dict>
</dict>
Loading a Mobile Backend's Configuration into a Xamarin iOS App
For any calls to MCS APIs using the iOS SDK to successfully complete, you need to have the mobile backend’s configuration loaded from the app’s OMC.plist
file. You do this using the OMCMobileBackend
class:
OMCMobileBackend oMCMobileBackend = OMCMobileBackendManager.SharedManager.MobileBackendForName("MBE_FullCoverage");
Authenticating and Logging In Using the SDK for Xamarin iOS
Here is some sample code that you can use for authentication through MCS in your iOS apps.
Oauth
You can use the following method to handle a user logging in with a user name and password.
OMCAuthorization authorization = oMCMobileBackend.Authorization;
authorization.AuthenticationType = OMCAuthenticationType.OAuth;
authorization.Authenticate(username.Text, password.Text);
This method terminates the connection to MCS and clears the user name and password from the iOS keychain:
authorization.Logout(HandleOMCAuthorizationLogoutCompletionBlock);
void HandleOMCAuthorizationLogoutCompletionBlock(NSError nsError)
{
if(nsError == null){
Console.WriteLine("Logout success!");
}
}
HTTP Basic
You can use the following method to handle a user logging in with a user name and password.
OMCAuthorization authorization = oMCMobileBackend.Authorization;
authorization.AuthenticationType = OMCAuthenticationType.HTTPBasic;
authorization.Authenticate(username.Text, password.Text);
This method terminates the connection to MCS and clears the user name and password from the iOS keychain:
authorization.Logout(HandleOMCAuthorizationLogoutCompletionBlock);
void HandleOMCAuthorizationLogoutCompletionBlock(NSError nsError)
{
if(nsError == null){
Console.WriteLine("Logout success!");
}
}
SSO
For apps that allow login through enterprise SSO, use:
OMCAuthorization oMCAuthorization = oMCMobileBackend.Authorization;
oMCAuthorization.AuthenticationType = OMCAuthenticationType.Sso;
oMCAuthorization.AuthenticateSSO(this, true, HandleOMCAuthorizationAuthCompletionBlock);
SSO with a Third-Party Token
First, your app needs to get a token from the third-party token issuer. The way you can obtain the token varies by issuer. For detailed information on obtaining third-party tokens and configuring identity providers in MCS, see Third-Party SAML and JWT Tokens.
Note:
The default expiration time for storing a third-party token in MCS is 6 hours. You can adjust this time by changing theSecurity_TokenExchangeTimeoutSecs
policy.
OMCAuthorization oMCAuthorization = oMCMobileBackend.Authorization;
oMCAuthorization.AuthenticationType = OMCAuthenticationType.SSOTokenExchange;
NSError nSError = oMCAuthorization.AuthenticateSSOTokenExchange(Token);
oMCAuthorization.AuthenticateSSOTokenExchange(Token, HandleOMCAuthorizationAuthCompletionBlock);
oMCAuthorization.AuthenticateSSOTokenExchange(Token, true, HandleOMCAuthorizationAuthCompletionBlock);
oMCAuthorization.AuthenticateSSOTokenExchange(Token, true);
bool iSLoaded = oMCAuthorization.LoadSSOTokenExchange;
oMCAuthorization.ClearSSOTokenExchange();
For apps that allow login through Facebook, use:
oMCAuthorization.AuthenticationType = OMCAuthenticationType.Facebook;
oMCAuthorization.AuthenticateSocial(HandleOMCAuthorizationAuthCompletionBlock);
If you haven’t already set up the app and its mobile backend to use Facebook as the identity provider, see Facebook Login in MCS.
Calling Platform APIs Using the SDK for Xamarin iOS
Once the mobile backend’s configuration info is loaded into the app and you have made a call to get the mobile backend, you can make calls to SDK classes to access platform features.
Here are some code snippets that illustrate how to access these APIs with the SDK.
User Management
Getting a User
OMCAuthorization oMCAuthorization = oMCMobileBackend.Authorization;
oMCAuthorization.GetCurrentUser(HandleOMCUserRegistrationCompletionBlockWithUser);
void HandleOMCUserRegistrationCompletionBlockWithUser(NSError nSError, OMCUser oMCUser)
{
if(nSError == null){
output.Text = user.FirstName + " User details have been fetched successfully";
}
}
Updating a User
user.SetValueForKey(new NSNumber(26),new NSString("age"));
user.SetValueForKey(new NSString("address"), new NSString("india"));
oMCAuthorization.UpdateCurrentUser(user,HandleOMCUserRegistrationCompletionBlock);
void HandleOMCUserRegistrationCompletionBlock(NSError nSError)
{
if (nSError == null)
{
//user = oMCUser;
if (user != null)
{
if (username.Text == null)
{
username.Text = "Welcome " + user.FirstName;
}
else output.Text = user.FirstName + " User details have been fetched successfully";
}
}
else
{
output.Text = nSError.ToString();
}
}
Location
Initialization
OMCLocation oMCLocation = oMCMobileBackend.Location;
Queries for Places, Devices, and Assets
private static OMCLocation oMCLocation;
private static OMCLocationPlace oMCLocationPlace;
private static OMCLocationDevice oMCLocationDevice;
private static OMCLocationAsset oMCLocationAsset;
oMCLocation = oMCMobileBackend.Location;
OMCLocationPlaceQuery oMCLocationPlaceQuery = oMCLocation.BuildPlaceQuery;
oMCLocationPlaceQuery.Name = "West";
oMCLocationPlaceQuery.ExecuteWithCompletionHandler(completionHandler);
OMCLocationAssetQuery oMCLocationAssetQuery = oMCLocation.BuildAssetQuery;
oMCLocationAssetQuery.Name = "joe";
oMCLocationAssetQuery.ExecuteWithCompletionHandler(completionHandler);
OMCLocationDeviceQuery oMCLocationDeviceQuery = oMCLocation.BuildDeviceQuery;
oMCLocationDeviceQuery.Name = "Beacon";
oMCLocationDeviceQuery.ExecuteWithCompletionHandler(completionHandler);
Fetching
Action<OMCLocationObjectQueryResult, NSError> completionHandler = new Action<OMCLocationObjectQueryResult, NSError>((OMCLocationObjectQueryResult arg1, NSError arg2) =>
{
if (arg2 == null)
{
OMCLocationObject[] LocationObjects = arg1.Items;
OMCLocationPlace oMCLocationPlace;
OMCLocationDevice oMCLocationDevice;
OMCLocationAsset oMCLocationAsset;
foreach (OMCLocationObject locationObject in LocationObjects)
{
Console.WriteLine("Location Object " + locationObject.GetType() + "--> " + i + " is: " + locationObject.ToString());
if(locationObject.GetType().Equals(typeof(OMCLocationPlace))){
oMCLocationPlace = (OMCLocationPlace)locationObject;
oMCLocation.PlaceWithID(oMCLocationPlace.Id_, placeCompletionHandler);
}
else if (locationObject.GetType().Equals(typeof(OMCLocationDevice)))
{
oMCLocationDevice = (OMCLocationDevice)locationObject;
oMCLocation.DeviceWithID(oMCLocationDevice.Id_, deviceCompletionHandler);
}
else if (locationObject.GetType().Equals(typeof(OMCLocationAsset)))
{
oMCLocationAsset = (OMCLocationAsset)locationObject;
oMCLocation.AssetWithID(oMCLocationAsset.Id_, assetCompletionHandler);
}
}
}
});
private static void assetCompletionHandler(OMCLocationAsset arg0, NSError arg1)
{
if (arg1 == null)
{
Console.WriteLine("Location Asset " + arg0.ToString());
}
}
private static void deviceCompletionHandler(OMCLocationDevice arg0, NSError arg1)
{
if (arg1 == null)
{
Console.WriteLine("Location Device " + arg0.ToString() );
}
}
private static void placeCompletionHandler(OMCLocationPlace arg0, NSError arg1)
{
if(arg1 == null){
Console.WriteLine("Location Place " + arg0.ToString());
}
}
Refreshing
Action<OMCLocationObjectQueryResult, NSError> completionHandler = new Action<OMCLocationObjectQueryResult, NSError>((OMCLocationObjectQueryResult arg1, NSError arg2) =>
{
if (arg2 == null)
{
OMCLocationObject[] LocationObjects = arg1.Items;
foreach (OMCLocationObject locationObject in LocationObjects)
{
Console.WriteLine("Location Object " + locationObject.GetType() + "--> " + i + " is: " + locationObject.ToString());
if(locationObject.GetType().Equals(typeof(OMCLocationPlace))){
oMCLocationPlace = (OMCLocationPlace)locationObject;
oMCLocationPlace.RefreshWithCompletionHandler(placeCompletionHandler);
}
else if (locationObject.GetType().Equals(typeof(OMCLocationDevice)))
{
oMCLocationDevice = (OMCLocationDevice)locationObject;
oMCLocationDevice.RefreshWithCompletionHandler(deviceCompletionHandler);
}
else if (locationObject.GetType().Equals(typeof(OMCLocationAsset)))
{
oMCLocationAsset = (OMCLocationAsset)locationObject;
oMCLocationAsset.RefreshWithCompletionHandler(assetCompletionHandler);
}
}
}
});
private static void placeCompletionHandler(NSError arg0)
{
if (arg0 == null)
{
Console.WriteLine("Location Place " + oMCLocationPlace.ToString());
}
}
private static void deviceCompletionHandler(NSError arg0)
{
if (arg0 == null)
{
Console.WriteLine("Location Device " + oMCLocationDevice.ToString());
}
}
private static void assetCompletionHandler(NSError arg0)
{
if (arg0 == null)
{
Console.WriteLine("Location Asset " + oMCLocationAsset.ToString());
}
}
Storage
Initialization
OMCStorage oMCStorage = oMCMobileBackend.Storage;
Getting a Collection
OMCStorageCollection oMCStorageCollection = oMCStorage.GetCollection("SharedCollection");
Getting an Object
oMCStorageObject = collection.Get("Object Id");
System.Console.WriteLine("Storage Object1: " + oMCStorageObject.ToString());
Getting All Objects from a Collection
NSMutableArray nSMutableArray = collection.Get(0, 100, true);
OMCStorageObject oMCStorageObject;
if (nSMutableArray != null && nSMutableArray.Count > 0)
{
for (uint i = 0; i < nSMutableArray.Count; i++){
oMCStorageObject = nSMutableArray.GetItem<OMCStorageObject>(i);
System.Console.WriteLine("Storage Object1: " + oMCStorageObject.ToString());
}
}
Uploading a Text File
NSData text = "This is a sample Text file";
OMCStorageObject txtFile = new OMCStorageObject("Mytext.txt", text, "text/plain");
collection.Put(txtFile);
Uploading an Image File
UIImage image = new UIImage("MyImage.png");
NSData data = image.AsPNG();
OMCStorageObject imageFile = new OMCStorageObject("MyImage", data, "image/png");
collection.Put(imageFile);
Notifications
Initialization
OMCNotifications oMCNotifications = oMCMobileBackend.Notifications;
Registering for Notifications
oMCNotifications.RegisterForNotifications(appDelegate.DeviceToken, HandleOMC_Notifications_SuccessBlock, HandleOMC_Notifications_ErrorBlock);
void HandleOMC_Notifications_SuccessBlock(NSHttpUrlResponse nSHttpUrlResponse)
{
if (nSHttpUrlResponse != null)
{
Console.WriteLine("Response from notification Server: " + nSHttpUrlResponse.StatusCode);
}
}
void HandleOMC_Notifications_ErrorBlock(NSError nSError)
{
if (nSError != null)
{
Console.WriteLine("Error in fetching mobiel file: " + nSError.LocalizedDescription);
}
}
AppDelegate code
public NSData DeviceToken = string.Empty;
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
DeviceToken = deviceToken; // Do something to storage deviceToken.
Console.WriteLine("Device Token: " + DeviceToken.ToString());
}
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
Console.WriteLine("FailedToRegisterForRemoteNotifications.. :(");
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
ProcessNotification(userInfo, false);
}
void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
{
// Check to see if the dictionary has the aps key. This is the notification payload you would have sent
if (null != options && options.ContainsKey(new NSString("aps")))
{
//Get the aps dictionary
NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;
string alertTitle = string.Empty;
string alert = string.Empty;
string sound = string.Empty;
int badge = -1;
//Extract the alert text
// NOTE: If you're using the simple alert by just specifying
// " aps:{alert:"alert msg here"} ", this will work fine.
// But if you're using a complex alert with Localization keys, etc.,
// your "alert" object from the aps dictionary will be another NSDictionary.
// Basically the JSON gets dumped right into a NSDictionary,
// so keep that in mind.
if (aps.ContainsKey(new NSString("alert")))
alert = (aps[new NSString("alert")] as NSString).ToString();
if (aps.ContainsKey(new NSString("alert")))
alert = (aps[new NSString("alert")] as NSString).ToString();
if (options.ContainsKey(new NSString("alertTitle")))
alertTitle = (options[new NSString("alertTitle")] as NSString).ToString();
//Extract the sound string
if (aps.ContainsKey(new NSString("sound")))
sound = (aps[new NSString("sound")] as NSString).ToString();
//Extract the badge
if (aps.ContainsKey(new NSString("badge")))
{
string badgeStr = (aps[new NSString("badge")] as NSObject).ToString();
int.TryParse(badgeStr, out badge);
}
if (!fromFinishedLaunching)
{
//Manually show an alert
if (!string.IsNullOrEmpty(alert))
{
UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
avAlert.Show();
}
}
}
}
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
ProcessNotification(userInfo, false);
}
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
ViewController viewController = new ViewController("LoginScreen", null);
Window.RootViewController = viewController;
Window.MakeKeyAndVisible();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
);
UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
//==== register for remote notifications and get the device token
// set what kind of notification types we want
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
// register for remote notifications
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
return true;
}
Analytics
Initialization
OMCAnalytics oMCAnalytics = oMCMobileBackend.Analytics;
Logging an Event
oMCAnalytics.LogEvent("this is test event "+ i +" from xamarin");
Setting Context Location
oMCAnalytics.SetContextLocationCountry("india", "Telangana", "Hyderabad", "500081");
Flushing an Event
oMCAnalytics.Flush();
App Policies
Loading the App Config and Getting Policies
oMCMobileBackend.AppConfigWithCompletionHandler(HandleOMCAppConfigCompletionBlock);
lock(obj){
Monitor.Wait(obj);
}
OMCAppConfig oMCAppConfig = oMCMobileBackend.AppConfig;
//Getting String
String str = oMCAppConfig.StringForProperty("Test_String", "No value configured");
Console.WriteLine("oMCAppConfig: String: " + str);
//Getting Number
NSNumber number = oMCAppConfig.NumberForProperty("Test_number", -1);
Console.WriteLine("oMCAppConfig: Number: " + number);
//Getting Boolean
Boolean boolean = oMCAppConfig.BooleanForProperty("Test_Boolean", false);
Console.WriteLine("oMCAppConfig: Boolean: " + boolean.ToString());
void HandleOMCAppConfigCompletionBlock(OMCAppConfig oMCAppConfig, NSError arg1)
{
if(arg1 == null){
Console.WriteLine("oMCAppConfig: " + oMCAppConfig.ToString());
}
}
Calling Custom APIs Using the SDK for Xamarin iOS
The SDK provides the CustomCodeClient
class to simplify the calling of custom APIs in MCS. You can call a REST method (GET, PUT, POST, or DELETE) on an endpoint where the request payload is JSON or empty and the response payload is JSON or empty.
Using this class, you invoke a REST method (GET, PUT, POST, or DELETE) on an endpoint where the request payload is JSON or empty and the response payload is JSON or empty.
In addition you can provide a completion handler to be called when the method invocation is complete (meaning that the handler runs asynchronously).
Use of CustomCodeClient
might look something like this:
oMCMobileBackend.CustomCodeClient.InvokeCustomRequest("mcs_examples_sync_salesplus/reminders", "get", null, HandleOMCCustomRequestCompletionHandler);
void HandleOMCCustomRequestCompletionHandler(NSError arg0, NSHttpUrlResponse arg1, NSObject nSObject)
{
if (nSObject != null)
{
System.Console.WriteLine("response object: " + nSObject.ToString());
}
}