Bu sayfa React-Native-Related-Digital SDK kurulum klavuzudur.
Kurulum
SDK içerisinde ihtiyaç duyulan kütüphaneyi kurun
npm install @react-native-community/async-storage
ya da
yarn add @react-native-community/async-storage
Alttaki komutu çalıştırarak React-Native-Related-Digital SDK’sını kurun
npm install react-native-related-digital
ya da
yarn add react-native-related-digital
Pod’ları yükleyin (Sadece IOS)
Alttaki komut satırlarını sırasıyla çalıştırın
cd ios pod install
Platform Entegrasyonları
Android
Bir Firebase projesi oluşturun. Size verilen Google-services.json dosyasını
android/app
klasörü altına kopyalayın. Örnek kullanımandroid/build.gradle
dosyanızın dependencies bölümüne aşağıdaki satırı ekleyin. Örnek kullanımclasspath 'com.google.gms: google-hizmetleri: 4.3.3'
android/app/build.gradle
dosyanızın en altına aşağıdaki satırı ekleyin. Örnek kullanımapply plugin: 'com.google.gms.google-services'
Uygulama ön plandayken bildirim almak için
AndroidManifest.xml
dosyanızınapplication
bölümüne aşağıdaki kodu ekleyin. Örnek kullanım<service android:name="com.relateddigital.reactnative.NotificationService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service>
iOS
Push Notifications ve Background Modes->Remote Notifications özelliklerini etkinleştirin.
AppDelegate.h
dosyanıza alttaki satırı ekleyin. Örnek kullanım#import <UserNotifications/UNUserNotificationCenter.h>
AppDelegate.h
dosyanızdaki @interface ile başlayan satıra UNUserNotificationCenterDelegate parametresini ekleyin. Son hali alttaki gibi olmalı. Örnek kullanım@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
AppDelegate.m
dosyanıza alttaki satırları ekleyin. Örnek kullanım#import "RelatedDigitalPushModule.h" #import <UserNotifications/UserNotifications.h>
AppDelegate.m
dosyanızdadidFinishLaunchingWithOptions
methodunun içerisindekireturn
ifadesinin hemen üzerine alttaki satırları ekleyin. Örnek kullanımUNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self;
AppDelegate.m
dosyanıza alttaki methodları ekleyin. Örnek kullanım- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RelatedDigitalPushModule didRegisterUserNotificationSettings:notificationSettings]; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RelatedDigitalPushModule didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RelatedDigitalPushModule didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RelatedDigitalPushModule didFailToRegisterForRemoteNotificationsWithError:error]; } -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); }
Görsel veya video gibi zengin içerikli push bildirim özelliklerini etkinleştirmek için alttaki adımları uygulayın.
1- Projenize Targets altındanNotification Service Extension
ekleyin ve isminiRelatedDigitalNotificationService
olarak değiştirin. Ardından bu hizmetin hedef iOS sürümünü 10.0 olarak değiştirin. Örnek kullanım
2- Yeni eklenmiş olanNotificationService.m
dosyasının içerisini alttakilerle değiştirin.
Örnek kullanım#import "NotificationService.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]; [RelatedDigitalNotificationService didReceiveNotificationRequest:self.bestAttemptContent withContentHandler:self.contentHandler]; } - (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. [RelatedDigitalNotificationService didReceiveNotificationRequest:self.bestAttemptContent withContentHandler:self.contentHandler]; } @end
3- Podfile dosyanızın kök seviyesine aşağıdaki satırları ekleyin. Örnek kullanımtarget 'RelatedDigitalNotificationService' do pod 'react-native-related-digital', :path => '../node_modules/react-native-related-digital' use_native_modules! end # Post Install processing for RelatedDigitalNotificationService causing errors def notification_service_post_install(installer) installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO' end end end
4- Podfile dosyanızın ana hedef bölümünenotification_service_post_install(installer)
satırını ekleyin, alttaki şekilde gözükmeli. Örnek kullanımpost_install do |installer| notification_service_post_install(installer) # Other post install function calls end