Press ESC to close

Xamarin Forms One Signal (Part 2)

Hello friends, after completing the transactions on One Signal, we can now make transactions on our project. For this we need to go to our project and install the One Signal package.

 

After adding the package, we need to start OneSignal in App.cs. You need the OneSignal key here. For this, we need to go to the Settings section in our project and go to the Key & IDs section. Here we need the OneSignal App Id.

Then we need to add OneSignal to the project. Here we can start the instant OneSignal.

OneSignal.Current.StartInit("6741e5dc-63ca-4761-bed8-9e17accbad03")
                .EndInit();

Then we need to make adjustments in the Android section. For Android adjustments, we first need to add a few lines in the manifest file. Paste the code below into the manifest file to allow it.

<permission android:name="${manifestApplicationId}.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
<uses-permission android:name="${manifestApplicationId}.permission.C2D_MESSAGE" />

Then make sure to write this code in the Application tags.

<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>

Our Android processes are over. Next we will do for iOS. It says that we do a lot of operations in One Signal documentation, but when we do these things, it cannot be said that it works very well. From my experience, we only need to come to the Info.plist file and open the notification permission.

After making the necessary adjustments, it is necessary to check when the notification is received and the notification is opened. For this we need to come to the App.cs file. We will add 2 more functions under the function we started OneSignal. When the notification comes here, if you want to show the notifications in the application with a list, you can save it to Local and show it to the user. The function that is triggered when the notification is opened is the function that should be directed to the notification. Clicking here, you can open the application and redirect according to the type of notification.

private void ConfigureOneSignal()
        {
            OneSignal.Current.StartInit("6741e5dc-63ca-4761-bed8-9e17accbad03")
                .HandleNotificationReceived((result) =>
                {

                })
                .HandleNotificationOpened((notification) =>
                {

                })
                .EndInit();
        }

We are now ready to send notifications via OneSignal. I’ll show you how to send it simply. If you like silent push, how to add test devices, how to send notifications from within the application, how to send notifications to certain users or if you have other questions, you can review OneSingal’s document or contact me.

After making the necessary adjustments, when you run the application, you can see how many devices are registered with your notification service.

To send a notification, you need to come to the messages section on OneSignal and say new notification from here. Then you need to enter a title and description. After entering this information, you can send notifications to all registered users.

In the meantime, a short reminder notifications are coming to Android emulators, but despite claiming that OneSignal is also working on iOS simulators, I couldn’t run it. So you can get healthier results in a physical device.

You can contact me by sending an e-mail or comment for places where you are stuck or want to ask.

Good work.

 

 

Comments (4)

  • kübrasays:

    Wednesday January 6th, 2021 at 12:55 PM

    Merhaba,

    Dökümanınız saysesinde xamarin üzerindeki simulasyona bildirim gönderebildim ancak uygulamaya android telefon bağladığımda bildirim gönderemiyorum OneSignal üzerinden şöyle bir dönüş alıyorum ‘Google Play Hizmetleri Kitaplığı Hatası’ AndroidManifest.xml inizde ‘com.google.android.gms.version’ dosyasının bulunduğundan emin olun .

    Konuyla ilgili yardımcı olabilir misiniz?

    • omersezersays:

      Wednesday January 6th, 2021 at 03:07 PM

      Selam Kübra,

      Daha önce böyle bir hata ile karşılaşmadım. Github üzerinden projene beni collabrator olarak eklersen inceleyebilirim. Github kullanıcı adım : omersezer

      İyi çalışmalar.

Leave a Reply

Your email address will not be published. Required fields are marked *