Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Notification Service Extension Ekleme

Notification Service Extension zengin push mesajları(görsel, video) almanıza yardımcı olur.

  1. Xcode’u açın ve File > New > Target adımını izleyin

  2. Notification Service Extension'ı seçin ve Next butonuna tıklayın.

  3. Product Name alanına NotificationService yazın ve Finish butonuna tıklayın.

  4. Finish butonuna tıkladıktan sonra açılacak diyalog penceresinde Cancel butonuna basın.

    Eğer Activate butonuna tıklarsanız uygulama Target'ı NotificationService olacaktır. Bu bir sorun değildir. Scheme alanından uygulamanızı seçerek düzeltebilirsiniz.

  5. Sol menüden projenizi seçin açılan alanda TARGETS altından NotificationService’i seçin. Deployment Info bölümünde Target alanını iOS 11.0 yapın.

  6. NotificationService.swift dosyasını açın ve içerisindeki kodları aşağıdaki kodlarla değiştirin.

import RelatedDigitalIOS
import UserNotifications

class NotificationService: UNNotificationServiceExtension {
    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        DispatchQueue.main.async {
            RelatedDigital.initialize(organizationId: urlConstant.shared.organizationId, profileId: urlConstant.shared.profileId, dataSource: "visistore", launchOptions: nil)

            RelatedDigital.enablePushNotifications(appAlias: "RDIOSExample", launchOptions: nil, appGroupsKey: "group.com.relateddigital.RelatedDigitalExample.relateddigital")
            RDPush.didReceive(self.bestAttemptContent, withContentHandler: contentHandler)
        }
    }

    override func serviceExtensionTimeWillExpire() {
        guard let contentHandler = contentHandler else {
            return
        }
        guard let bestAttemptContent = bestAttemptContent else {
            return
        }
        contentHandler(bestAttemptContent)
    }
}

Notification Content Extension Ekleme

Not: Eğer push mesajı gönderimlerinizde Carousel Push kullanacaksanız bunu eklemeniz zorunludur.

  1. Xcode’u açın ve File > New > Target adımını izleyin

  2. Notification Content Extension'ı seçin ve Next butonuna tıklayın.

  3. Pproduct Name alanına NotificationContent yazın ve Finish butonuna tıklayın.

  4. Finish butonuna tıkladıktan sonra açılacak diyalog penceresinde Cancel butonuna tıklayın.

    1. Eğer Activate butonuna tıklarsanız uygulama Target'ı NotificationContent olacaktır. Bu bir sorun değildir. Scheme alanından uygulamanızı seçerek düzeltebilirsiniz.

  5. Sol menüden projenizi seçin açılan alanda TARGETS altından NotificationContent’i seçin. Deployment Info bölümünde Target alanını iOS 11.0 yapın.

  6. MainInterface.storyboard ve NotificationContent.swift dosyalarını silin. Ardından NotificationContent klasörü altına RDNotificationViewController isminde swift dosyası oluşturun. Info.plist dosyasını bu linkteki ile aynı olduğuna dikkat ediniz.

    Objective-C Bridging Header oluşturma sorulursa Don’t Create butonuna tıklayın.

  7. EMNotificationViewController.swift açın ve içerisindeki kodları aşağıdaki ile değiştirin.

import UIKit
import UserNotifications
import UserNotificationsUI
import RelatedDigitalIOS

@objc(RDNotificationViewController)
class RDNotificationViewController: UIViewController, UNNotificationContentExtension {
    
    let carouselView = PushNotificationCarousel.initView()
    var completion: ((_ url: URL?, _ bestAttemptContent: UNMutableNotificationContent?) -> Void)?
    
    var notificationRequestIdentifier = ""
    
    func didReceive(_ notification: UNNotification) {
        notificationRequestIdentifier = notification.request.identifier
        RelatedDigital.initialize(organizationId: "YOUR_ORGANIZATION_ID", profileId: "YOUR_PROFILE_ID", dataSource: "YOUR_DATA_SOURCE", launchOptions: nil)
        RelatedDigital.enablePushNotifications(appAlias: "YOUR_APP_ALIAS", launchOptions: nil, appGroupsKey: "YOUR_APP_GROUPS_KEY")
        carouselView.didReceive(notification)
    }
    func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
        carouselView.didReceive(response, completionHandler: completion)

    }
    override func loadView() {
        completion = { [weak self] url, bestAttemptContent in
            if let identifier = self?.notificationRequestIdentifier {
                UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [identifier])
                UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { notifications in
                    bestAttemptContent?.badge = NSNumber(value: notifications.count)
                })
            }
            if let url = url {
                if #available(iOSApplicationExtension 12.0, *) {
                    self?.extensionContext?.dismissNotificationContentExtension()
                }
                self?.extensionContext?.open(url)
            } else {
                if #available(iOSApplicationExtension 12.0, *) {
                    self?.extensionContext?.performNotificationDefaultAction()
                }
            }
        }
        carouselView.completion = completion
        carouselView.delegate = self
        self.view = carouselView
    }
}

/**
 Add if you want to track which carousel element has been selected
 */
extension RDNotificationViewController: PushCarouselDelegate {
    func selectedItem(_ element: RDPushMessage.Element) {
        // Add your work...
        print("Selected element is => \(element)")
    }
}

NotificationContent ve NotificationService için Related Digital iOS SDK’sını eklemeliyiz. Cocoapods ve SPM için farklı tanımlamalar mevcuttur.

Cocoapods

Podfile dosyanızı aşağıdaki şekilde düzenleyin ve tekrar terminalden proje dizininize giderek pod install yazarak enter tuşuna basın.

platform :ios, '11.0'

target 'YOUR_PROJECT_NAME' do
  use_frameworks!
  pod 'RelatedDigitalIOS'
post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'RelatedDigitalIOS'
            target.build_configurations.each do |config|
                config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
            end
        end
    end
end
end

target 'NotificationService' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'RelatedDigitalIOS'
  # Pods for RelatedDigital

end

target 'NotificationContent' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'RelatedDigitalIOS'
  # Pods for RelatedDigital

end

SPM

Hem NotificationService hem de NotificationContent için General altında Frameworks and Libraries altına RelatedDigitalIOS modülünü eklemelisiniz.

App Groups Ekleme

Tüm hepsini tamamladıktan sonra Targetlara App Groups eklemeniz gerekmektedir.

Görselde sol tarafta işaretlenmiş olan Targetlarda sırasıyla Signing & Capabilities altından App Groups ekleyin. App Groups adını group.YOUR_APP_BUNDLE_IDENTIFIER.relateddigital şeklinde yazın.

Push Bildirim İzni Alma

Kullanıcılardan iki farklı şekilde izin alabilirsiniz. Bunlardan birincisi Provisional Push. Provisional Push’ta kullanıcının önüne uygulama tarafından herhangi bir izin sorulmaz. Gönderdiğiniz ilk pushta Bildirim Merkezinde kullanıcıya bildirim gönderimini açık bırakma ve kapatma seçenekleri sunulur.

Diğeri ise standart bildirim izni popupı. Kullanıcı appi açtığında popup olarak sunulur.

Provisional Push

Eğer provisional push izni alınmak isteniyorsa didFinishLaunchingWithOptions’a aşağıdaki kodu ekleyin. iOS 12 ya da daha eski versiyon kullanıcıları için bu fonksiyon askForNotificationPermission şeklinde çalışacaktır.

        UNUserNotificationCenter.current().delegate = self
        RelatedDigital.enablePushNotifications(appAlias: "YOUR_APP_ALIAS", launchOptions: launchOptions, appGroupsKey: "YOUR_APP_GROUP_KEY")
        RelatedDigital.registerForPushNotifications()
        RelatedDigital.askForNotificationPermissionProvisional()
        if #available(iOS 13, *) {
            // handle push for iOS 13 and later in sceneDelegate
        }
        else if let userInfo = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Any] {
            RelatedDigital.handlePush(pushDictionary: userInfo)
        }
        return true

Eğer provisional push izni almak istemiyorsanız didFinishLaunchingWithOptions’a aşağıdaki kodu ekleyin.

        UNUserNotificationCenter.current().delegate = self
        RelatedDigital.enablePushNotifications(appAlias: "YOUR_APP_ALIAS", launchOptions: launchOptions, appGroupsKey: "YOUR_APP_GROUP_KEY")
        RelatedDigital.registerForPushNotifications()
        RelatedDigital.askForNotificationPermission()
        if #available(iOS 13, *) {
            // handle push for iOS 13 and later in sceneDelegate
        }
        else if let userInfo = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Any] {
            RelatedDigital.handlePush(pushDictionary: userInfo)
        }
        return true

Eğer kullanıcılar bildirim göndermeye izin verirse aşağıdaki metod çalışır ve APNS’ten token alınarak Euromessage sistemlerine kaydolur.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        RelatedDigital.registerToken(tokenData: deviceToken)
    }

Push Açıldı Raporunu İletme

RMC paneli üzerinden kullanıcılarınızın push mesajlarına tıklayıp tıklamadıklarını raporlayabilmek için aşağıdaki kodları ekleyin.

 func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        RelatedDigital.handlePush(pushDictionary: userInfo)
    }

    func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        RelatedDigital.handlePush(pushDictionary: userInfo)
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .badge, .sound])
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        RelatedDigital.handlePush(pushDictionary: response.notification.request.content.userInfo)
        completionHandler()
    }

SceneDelegate.swift

willConnectTo fonksiyonun içerisine aşağıdaki kod bloğunu ekleyin.

if #available(iOS 13, *),
    let userInfo = connectionOptions.notificationResponse?.notification.request.content.userInfo {
    RelatedDigital.handlePush(pushDictionary: userInfo)
}    

RMC’ye bilgi gönderme

Aşağıdaki kodu kullanıcı uygulamanıza üye olduğunda, üye girişi yaptığında ve uygulama ilk açılırken çalıştırın.

Eğer kullanıcı e-mail izni vermemişse permission değerini false olarak göndermelisiniz.

RelatedDigital.setEmail(email: "test@relateddigital.com", permission: true)
RelatedDigital.setEuroUserId(userKey: "1234567890")
RelatedDigital.sync()

Mobil kanaldan gelen datalarınızın RMC'ye yüklenebilmesi için, aktif RMC hesabınızda kullanmış olduğunuz referans değeriniz ne ise (KEY_ID* veya E-Mail) mobil kanaldan gelen dataların da bu referans ile gelmesine dikkat ediniz."

*KEY_ID: Uygulama sahibi tarafından müşterisinin tekilleştirilmesi için kullanılan id değerleridir. Bunlar CRM id, userid, customerid, accountid gibi farklı isimlerle ifade ediliyor olabilir.

IYS E-Posta Kaydı

IYS kodunu Euromsg.sync() kodundan hemen önce ekleyiniz.

RelatedDigital.registerEmail(email: "example@email.com", permission: true)
//TACIR hesaplar için aşağıdaki kodu kullanınız
RelatedDigital.registerEmail(email: "example@commercial.com, permission: True, isCommercial: true)

  • No labels