/
React Native- Firebase

React Native- Firebase

React Native Related Digital sdk’sının Firebase Messaging sdk’sı ile birlikte çalışabilmesi için alttaki ayarlamaların yapılması gerekiyor.

Firebase sdk’nın 17.3.2 sürümünü kullanmanız önerilir.

Örnek entegrasyonu görmek için GitHub - relateddigital/react-native-related-digital at cocacola

Package.json

"@react-native-firebase/app": "^17.3.2", "@react-native-firebase/messaging": "^17.3.2"

iOS

  1. Podfile içerisine alttaki kodlar eklenmeli;
    Bu kısım ana seviyeye.

    pod 'Firebase', :modular_headers => true pod 'FirebaseCoreInternal', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true pod 'FirebaseCore', :modular_headers => true pod 'FirebaseSessions', :modular_headers => true pod 'FirebaseCoreExtension', :modular_headers => true pod 'FirebaseInstallations', :modular_headers => true pod 'GoogleDataTransport', :modular_headers => true pod 'nanopb', :modular_headers => true pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'


    Bu kısım RelatedDigitalNotificationService target'ı içerisine eklenmeli.

    target 'RelatedDigitalNotificationService' do use_react_native! pod 'Firebase/Messaging', '~> 10.7.0' <----- SADECE BU SATIR EKLENECEK DİĞER SATIRLAR ÖNCEDEN EKLENMİŞ OLMALI pod 'react-native-related-digital', :path => '../node_modules/react-native-related-digital' end

     

  2. AppDelegate.mm dosyasına alttaki import satırı eklenmeli;

    #import <Firebase.h>

     

  3. ios/RelatedDigitalNotificationService/NotificationService.m dosyasının içeriğini alttakiyle değiştirin.

    #import "NotificationService.h" #import "FirebaseMessaging.h" #import "RelatedDigitalNotificationService.h" @interface NotificationService () @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; @end @implementation NotificationService - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; if (self.bestAttemptContent) { NSMutableDictionary *userInfo = self.bestAttemptContent.userInfo.mutableCopy; NSString *emPushSp = userInfo[@"emPushSp"]; if (emPushSp) { NSLog(@"emPushSp: %@", emPushSp); [userInfo removeObjectForKey:@"fcm_options"]; self.bestAttemptContent.userInfo = userInfo; [RelatedDigitalNotificationService didReceiveNotificationRequest:@"rniostestapptest" withBestAttemptContent:self.bestAttemptContent withContentHandler:self.contentHandler]; } else { [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler]; } } // Modify the notification content here... //self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title]; //self.contentHandler(self.bestAttemptContent); } - (void)serviceExtensionTimeWillExpire { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. self.contentHandler(self.bestAttemptContent); } @end

     

  4. ios/RelatedDigitalTestClient/AppDelegate.mm içerisindeki didFinishLaunchingWithOptions fonksiyonunun return satırından hemen öncesine alttaki satırı ekleyin;

    [FIRApp configure];

     

  5. Aynı ios/RelatedDigitalTestClient/AppDelegate.mm dosyasına alttaki fonksiyonu ekleyin;

    -(void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { void (^exampleCompletionHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result) { switch (result) { case UIBackgroundFetchResultNewData: NSLog(@"Yeni veri."); break; case UIBackgroundFetchResultNoData: NSLog(@"Veri yok veya veri değişmemiş."); break; case UIBackgroundFetchResultFailed: NSLog(@"Veri çekme başarısız."); break; default: NSLog(@"UIBackgroundFetchResult hata."); break; } }; [RelatedDigitalPushModule didReceiveRemoteNotification:response.notification.request.content.userInfo fetchCompletionHandler: exampleCompletionHandler]; }

 

Android

RMC’yi , push mesajlaşma için FCM kullanan diğer SDK'larla birlikte kullanabilirsiniz. Bunu yapmak için, servisler arasında eventleri dağıtmak için bir Router(Yönlendirici) servisi oluşturmalısınız.

Eklenecek router servisi manifest dosyası içerisinde diğer FCM servislerinin üstünde olmalıdır.

  1. İlk olarak AndroidManifest.xml dosyasına oluşturacağınız servisi ekleyin.

    <service android:name="com.yourpackage.RouterFCMService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

     

  2. MainApplication.java sınıfı ile aynı dizinde yeni java sınıfı oluşturup, RouterFCMService şeklinde isimlendirin.
    android/app/src/main/java/com/yourappname/RouterFCMService.java

    import android.util.Log; import java.util.Map; import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.FirebaseMessagingService; import euromsg.com.euromobileandroid.service.EuroMsgFCMHelper; public class RouterFCMService extends FirebaseMessagingService { private static final String TAG = "FCMService"; @Override public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> data = remoteMessage.getData(); String emPushSp = data.get("emPushSp"); if(emPushSp != null) { EuroMsgFCMHelper.onMessageReceived(this,remoteMessage); } else { dispatchNonRMCMessage(remoteMessage); } } @Override public void onNewToken(String token) { Log.d(TAG, "Refreshed token: " + token); EuroMsgFCMHelper.onNewToken(this,token); } private void dispatchNonRMCMessage(RemoteMessage remoteMessage) { // RMC Harici Push işleme mantığınızı buraya uygulayın } }

dispatchNonRMCMessage fonksiyonu içerisinde RMC dışındaki FCM servislerinden gelen push bildirimlerini işleyebilirsiniz.

Related content

Copyright 2020 Related Digital