728x90

iOS

 

github.com/xamarin/GoogleApisForiOSComponents/blob/master/docs/Firebase/CloudMessaging/GettingStarted.md

 

xamarin/GoogleApisForiOSComponents

Contribute to xamarin/GoogleApisForiOSComponents development by creating an account on GitHub.

github.com

xamarinlatino.com/xamarin-forms-firebase-cloud-messaging-ios-setup-1961a91d4055

 

Xamarin Forms & Firebase Cloud Messaging: iOS Setup

En mis últimas publicaciones, he hablado de cómo integrar OneSignal (una plataforma que facilita el envío de Push Notifications a…

xamarinlatino.com

docs.microsoft.com/ko-kr/xamarin/ios/platform/user-notifications/deprecated/remote-notifications-in-ios

 

IOS의 푸시 알림 - Xamarin

이 문서에서는 iOS 9 및 이전 버전에서 푸시 알림을 사용 하는 방법을 설명 합니다. 인증서에 대해 설명 하 고 APNS (Apple Push Notification Gateway Service) 등에 등록 합니다.

docs.microsoft.com

Android

github.com/iBobb/xamarin_firebaseapi

 

iBobb/xamarin_firebaseapi

An example project for using the newest APIs to send push notifications using the Firebase - iBobb/xamarin_firebaseapi

github.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Media;
using Android.OS;
using Android.Runtime;
using Android.Support.V4.App;
using Android.Util;
using Android.Views;
using Android.Widget;
using Firebase.Messaging;

namespace XamarinFirebaseExample.Droid
{
    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class MyFirebaseMessagingService : FirebaseMessagingService
    {
        private const string defaultNotificationTitle = "App name";
        private const string newsChannelId = "1"; // not sure I just use 1 you should be able to use anything as long as its unique per channel
        private const string newsChannelDescription = "Channel name shown to user e.g. News";
        private long[] vibrationPattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500 };
        private NotificationManager notificationManager;

        public override void OnNewToken(string newToken)
        {
            base.OnNewToken(newToken);
            Log.Info("MyFirebaseMessagingService", "Firebase Token: " + newToken);
            saveRegistrationToApp(newToken);
        }

        public override void OnMessageReceived(RemoteMessage remoteMessage)
        {
            base.OnMessageReceived(remoteMessage);
            // depending on how you send the notifications you might get the message as per documentation
            // using remoteMessage.getNotification().getBody()
            var message = remoteMessage.Data["message"];
            Log.Debug("MyFirebaseMessagingService", "From:    " + remoteMessage.From);
            Log.Debug("MyFirebaseMessagingService", "Message: " + message);

            sendNotification(defaultNotificationTitle, message);
        }

        private void sendNotification(string title, string message)
        {
            var intent = new Intent(this, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.SingleTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
            notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                NotificationImportance importance = NotificationImportance.High;
                NotificationChannel notificationChannel = new NotificationChannel(newsChannelId, newsChannelDescription, importance);
                notificationChannel.EnableLights(true);
                notificationChannel.LightColor = Color.Red;
                notificationChannel.EnableVibration(true);
                notificationChannel.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification), new AudioAttributes.Builder()
            .SetContentType(AudioContentType.Sonification)
            .SetUsage(AudioUsageKind.Notification)
            .Build());
                notificationManager.CreateNotificationChannel(notificationChannel);
            }

            Notification notification = new NotificationCompat.Builder(this, newsChannelId)
                .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Mipmap.icon)) //newest projects use mipmaps and drawables, you can go to drawables too
                .SetSmallIcon(Resource.Mipmap.icon)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetAutoCancel(true)
                .SetVisibility((int)NotificationVisibility.Private)
                .SetContentIntent(pendingIntent)
                .SetVibrate(vibrationPattern)
                .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                .Build();

            notificationManager.Notify(0, notification); // overrides old notification if it's still visible because it uses same Id
        }

        private void saveRegistrationToApp(string token)
        {
           // send to server or store locally
        }
    }
}
728x90
Posted by kjun.kr
,