Search This Blog

Wednesday 26 September 2018

Set Custom Content on Xamarin Form (New Feature in 3.2.0) Navigation Toolbar

In Xamarin Forms 3.2.0  you can set the custom Navigation Icon & Navigation Text.




<ContentPage>
<NavigationPage.TitleView >
   <StackLayout HorizontalOptions="Start" Orientation="Horizontal">
<Image  HeightRequest="50" WidthRequest="50"  Source="Icon"></Image>
                <Label VerticalOptions="Center" Text="Pragnesh Mistry"  TextColor="White"    />
          </StackLayout>
</NavigationPage.TitleView>
</ContentPage>

Sunday 16 September 2018

Xamarin Forms Timer

Xamarin Form Timer:

Xamarin Form Timer will execute the block of code in specified time interval.


 

// Here is the example that on the click of  Start Button The timer will execute the block of code for every second and update the Label Text & On the Click of Stop Button Timer will stop.

private void btnStartTimer_Clicked(object sender, EventArgs e)
{
    if (btnStartTimer.Text == "Start")
    {
        returnValue = true;
        btnStartTimer.Text = "Stop";
    }
    else
    {
        btnStartTimer.Text="Start";
        returnValue = false;
    }
    int count = 0;
    lblTimer.Text = "";
    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
        // Do something
        count += 1;
        Device.BeginInvokeOnMainThread(() =>
        {
            lblTimer.Text = count.ToString() ;
        });
            return returnValue; // True = Repeat again, False = Stop the timer
    });
}

Wednesday 12 September 2018

Push Notification in Xamarin Form using OneSignal

What is OneSignal
OneSignal is a high volume and reliable push notification service for website and mobile application.

Add NuGet Package
From the solution explorer right click on your project and select Manage NuGet Package Option
then search for the OneSignal and install it.


Android/iOS SDK Setup
  • A OneSignal Account, if you do not already have one
  • Your OneSignal App ID, available in Keys & IDs
  • A Google/Firebase Server API Key
  • An iOS Push Certificate. Generate one here using our provisionator tool.
  • An iOS device (iPhone, iPad, iPod Touch) to test on. The Xcode simulator doesn't support push notifications so you must test on a real device.
  • A Mac with a new version of Xcode
Login With Google or Create Account in OneSignal Then Click on Add App Button To Add new App
Then Select the platform to configure.


For Android Google Freebase Server Key required that you will get from Google freebase console.


For iOS Generate the iOS Push Certifcate and upload it.


From the Keys & IDs you will get the OneSignal APP ID

Add the following code to your App.xaml.cs
using Com.OneSignal;

public App()
{
 InitializeComponent();
 MainPage = new OneSignalXamarinFormsExamplePage();

 OneSignal.Current.StartInit("YOUR_ONESIGNAL_APP_ID")
                 .EndInit();



//when you call the StartInit() method your device player id will register with

// the one signal you can check that from the www.onesignal.com website.

}






UserIDs (getting onesignal playerID)
The OneSignal PlayerID is a UUID (Unique Universal Identifier) that OneSignal gives all devices that use your mobile app or subscribe to your site.

Com.OneSignal.OneSignal.Current.IdsAvailable(getID); //Handle this method
private void getID(string playerID, string pushToken)
{
  // write logic for store playerID in the db
}
 you can write the logic like whenever the app start at that time player id will be stored in database.


Android Setup
<application ....>
 <receiver android:name="com.onesignal.GcmBroadcastReceiver"
           android:permission="com.google.android.c2dm.permission.SEND" >
   <intent-filter>
     <action android:name="com.google.android.c2dm.intent.RECEIVE" />
     <category android:name="${manifestApplicationId}" />
   </intent-filter>
 </receiver>
</application>

Replace all 3 of instances of ${manifestApplicationId} with your package name in AndroidManifest.xml.

iOS Setup
In your application's Info.plist, verify your Bundle Identifier matches you App Settings' Bundle ID,
Enable Background Modes, allow Remote notifications.
Sending push notification to registered device
var viewButton = new Dictionary<string, string>();
viewButton.Add("id", "openCompendium"); viewButton.Add("text", "View"); viewButton.Add("icon", "mail24"); //viewButton this button will display when the notification received in mobile. string postedBy = MasterDetailView.selectedEmail; var notification = new Dictionary<string, object>(); notification["headings"] = new Dictionary<string, string>() { { "en", "New Post Added" } }; notification["contents"] = new Dictionary<string, string>() { { "en", "Xyz Has added a new post for you" } }; notification["include_player_ids"] = new List<string>() { playerID }; //here you can specify the player id notification["buttons"] = new List<object> { viewButton }; // here you can add multiple button //by seperated by comma notification["small_icon"] = "icon20"; notification["priority"] = 10; notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(1).ToString("U"); Com.OneSignal.OneSignal.Current.PostNotification(notification);

Handle action button click in one signal

Com.OneSignal.OneSignal.Current.StartInit("OnesigalAppID"). HandleNotificationOpened(HandleNotificationOpened).EndInit(); private void HandleNotificationOpened(OSNotificationOpenedResult result) { string actionID = result.action.actionID;
// whatever the action id register while sending notification that will return here. }




Thursday 6 September 2018

How to autosize Editor height

An Editor can be made to auto-size to its content by setting the
Editor.AutoSize property to TextChanges,
which is a value of the EditoAutoSizeOption enumeration.
This enumeration has two values: Disabled indicates that automatic resizing is disabled,
and is the default value. TextChanges indicates that automatic resizing is enabled.


<Editor Text="Enter text here" AutoSize="TextChanges" />

Popular Posts