Sunday, 27 January 2019

User Defaults in Xamarin.IOS

IOS provides many ways of storing data of an application. One of this way is called NSUserDefaults. NSUserDefaults allow you to save and retrieve data in the form of key, value pair.

NSUserDefaults class provides its own built in mechanisms to save float, double, integers, Boolean and URL data. To save a custom object it should be converted to NSData object using NSUserDefaults.
Storing
    NSUserDefaults.StandardUserDefaults.SetString("value", "key");

Example1:

       NSUserDefaults values = new NSUserDefaults();  

// Store value on Userdefaults  
values .SetString(txtString.Text, "stringvalue");  

values .SetInt(Int32.Parse(txtInteger.Text), "integervalue");  

// Get values form Userdefaults  

lblString.Text = values .StringForKey("stringvalue");  
lblInteger.Text = values .IntForKey("integervalue").ToString();  
lblBoolean.Text = values .BoolForKey("swithvalue").ToString();  



    NSUserDefaults.StandardUserDefaults.Synchronize();
Retrieve

NSUserDefaults.StandardUserDefaults.StringForKey("key");
Clear:

NSUserDefaults.StandardUserDefaults.RemoveObject("key");



Example 2: 

public partial class ViewController : UIViewController  
{  
public static string UserNameKey = "user_name";  

protected ViewController(IntPtr handle) : base(handle)  
{  
// Note: this .ctor should not contain any initialization logic.  
}  

public override void ViewDidLoad()  
{  
base.ViewDidLoad();  
  
SaveUserName(UserNameKey, "Subramanyam");  
 
var readUserName = ReadUserName();  
}  

public override void DidReceiveMemoryWarning()  
{  
base.DidReceiveMemoryWarning();  
// Release any cached data, images, etc that aren't in use.  
}  

void SaveUserName(string key, string value){  
var plist = NSUserDefaults.StandardUserDefaults;  
plist.SetString(value, key);   
plist.Synchronize();  
}  

string ReadUserName( )  
{  
return NSUserDefaults.StandardUserDefaults.StringForKey(UserNameKey);  
}  

Friday, 25 January 2019

Android Bottom Tabs

After Release of Xamarin Forms 3.x now we can set tab to bottom in android platform.


Code Behind :


    using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;

 
 On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

OR 
 
   On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);


From XAML :
 
 <?xml version="1.0" encoding="utf-8"?>
 <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
 xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
 android:TabbedPage.ToolbarPlacement="Bottom"
example
 
Lets add a TabbedPage and include android:TabbedPage.ToolbarPlacement="Bottom" in the head of Page as shown below in XAML code.

 <?xml version="1.0" encoding="utf-8" ?>
 <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
 x:Class="App1.TabbedPage1"
 xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
 android:TabbedPage.ToolbarPlacement="Top"
>
 
 <!--Pages can be added as references or inline-->
 <ContentPage Title="Tab 1" />
 <ContentPage Title="Tab 2" />
 <ContentPage Title="Tab 3" />
 </TabbedPage> 

Here, We have three options to set the position of Tabbar in android. i.e. Top, Bottom and Default.

 android:TabbedPage.ToolbarPlacement="Top"



sets the Tabbar to appear at the top whereas ,

 android:TabbedPage.ToolbarPlacement="Bottom"



Complete Guide: Building a Live Cricket Streaming App for 100M Users

Comprehensive guide to building a scalable live cricket streaming platform for 100M users, covering backend infrastructure, streaming techno...