Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

Bu sayfada bulabilecekleriniz:

Table of Contents
minLevel1
maxLevel6
outlinefalse
styledecimal
typelist
printablefalse
separatorbrackets

Notification Service Extension Ekleme

...

  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.

    Code Block
    languageswift

...

  1. 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: "YOUR_ORGANIZATION_ID", profileId: "YOUR_SITE_ID", dataSource: "YOUR_DATA_SOURCE", launchOptions: nil)
    
                RelatedDigital.enablePushNotifications(appAlias: "YOUR_APP_ALIAS", launchOptions: nil, appGroupsKey: "YOUR_APP_GROUPS_KEY")
                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

...

  1. "Copy only when installing" seçili olmadığından emin olun. Öncelikle Main Targetınızı seçin ardından Build Phases > Embed App Extensions'ı açın. Burada eğer Copy only when installing seçili ise seçimi kaldırın. Bu seçili olması halinde pushlarınızda görsel kullanamazsınız.

    Image Added

Notification Content Extension Ekleme

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

...

Code Block
languageswift
 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) {
        if completionHandler([.alert, .badge, .sound])#available(iOS 14.0, *) {
    }      func userNotificationCenter(_ center: UNUserNotificationCenter,
 completionHandler([.banner, .sound, .badge, .list])
        } else {
            completionHandler([.alert, .badge, .sound])
     didReceive response: UNNotificationResponse, }
    }

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

SceneDelegate.swift

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

Code Block
languageswift
if #available(iOS 13, *),     let userInfo = connectionOptions.notificationResponse?.notification.request.content.userInfo {     RelatedDigital.handlePush(pushDictionary: userInfo)
}  withCompletionHandler completionHandler: @escaping () -> Void) {
        RelatedDigital.handlePush(pushDictionary: response.notification.request.content.userInfo)
        completionHandler()
    

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.

...

}

SceneDelegate.swift

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

Code Block
languageswift
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.

Code Block
languageswift
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)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.

Code Block
languageswift
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.

Code Block
languageswift
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)

Push Bildirim Mesajlarını Kullanma

Son 30 gün içerisinde gönderilmiş push bildirim mesajlarına aşağıdaki gibi erişebilirsiniz.

Mesajlar tarihe göre sıralanmıştır. Son gelen mesaj listenin ilk başında gösterilir.

message.encoded ile payloadı görebilir bir alt leveldaki parametreye hangi yolla ulaşabileceğinizi öğrenebilirsiniz.

Örneğin push başlığı için message.aps?.alert?.title kullanabilirsiniz

Code Block
RelatedDigital.getPushMessages { messages in
                if messages.isEmpty {
                    print("🚲 there is no recorded push message.")
                }

                for message in messages {
                    print("🆔: \(message.pushId ?? "")")
                    print("📅: \(message.formattedDateString ?? "")")
                    print(message.encoded)
                }
            }

Eğer kullanıcı bazlı bu mesajları ayırmak isterseniz aşağıdaki kodu kullanmalısınız.

Öncelikle app açılırken aşağıdaki kod ile kullanıcı için bir id tanımlamalısınız.

Code Block
RelatedDigital.setNotificationLoginID(notificationLoginID: "123 veya umut@relateddigital.com")

Ardından aşağıdaki kodu kullanarak id bazlı pushları ayırabilirsiniz.

Code Block
RelatedDigital.getPushMessagesWithID { messages in
                if messages.isEmpty {
                    print("🚲 there is no recorded push message.")
                }

                for message in messages {
                    print("🆔: \(message.pushId ?? "")")
                    print("📅: \(message.formattedDateString ?? "")")
                    print(message.encoded)
                }
            }

Push Bildirim Sesi Kullanma

iOS Custom Sound eklemek için projenizin root dizinine .wav .mp3 .ogg uzantıları kabul edilen ses dosyalarınızı maksimum 2 adet olacak şekilde ekleyebilirsiniz.

Bu adımdan sonra Ayarlar > Kampanya Ayarları > Push Uygulamaları > UYGULAMANIZIN_ISMI adımından Özel Ses Dosyası 1 ve Özel Ses Dosyası 2 alanlarına ses dosyalarınızın ismini/isimlerini yazmanız gerekmektedir.

...

Action Button Callback Kullanma

Action Button kullandığınız pushlarda kullanıcının tıkladığı butona göre yönlendirme yapabilmek için Action Button delege methodunu kullanmalısınız.

Öncelikle AppDelegate class'ına PushAction protokolünü ekleyin.

Code Block
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, PushAction {
  ...
}

Ardından aşağıdaki fonksiyonu AppDelegate class'ının içerisine ekleyerek kullanabilirsiniz.

Code Block
func actionButtonClicked(identifier: String, url: String) {
        print(identifier,url)
}

Son hali aşağıdaki ekran görüntüsündeki gibi olacaktır.

...

Push Mesajlarını Okundu Olarak İşaretleme

getPushMessages fonksiyonunda kullanıcılarınıza uygulama içerisinde gösterdiğiniz push mesajların okundu bilgisini işaretlemek için aşağıdaki fonksiyonları kullanabilirsiniz. Bu fonksiyonlar ile getPushMessages içerisinde bulunan payload/payloadlarda ki status durumunu O yapar ve buna göre kendi oluşturduğunuz bildirim merkezinde buna göre aksiyon alabilirsiniz. Bu fonksiyonları kullandığınız zaman size geri dönüş olarak true veya false döner.

Tümünü okundu olarak işaretleme

Code Block
languageswift
RelatedDigital.readAllPushMessages { success in
            print(success)
        }

Bildirim bazlı okundu olarak işaretleme

Code Block
RelatedDigital.readAllPushMessages(pushId: "BURAYA_PUSH_ID_GELECEK") { success in
            print(success)
        }

getPushMessage fonksiyonunda payloadda pushId bulunmaktadır buraya o değeri ekleyeceksiniz.

Push Mesajlarını Silme

deleteAllPayloads ve deleteAllPayloadWithId fonksiyonlarını kullanarak getPushMessages fonksiyonumuz ile uygulamanız içerisinde gösterdiğiniz pushları silinde olarak işaretleyebilirsiniz.

Tüm bildirimleri silme

Code Block
RelatedDigital.deleteAllPayloads { completed in
            print(completed)
        }

Bildirim bazlı silme

Code Block
RelatedDigital.deletePayloadWithId(pushId: "1234567890") { completed in
            print(completed)
        }

Related Digital ile Firebase’i Ortak Kullanma

Uygulamanızda Related Digital SDK’mızı ve Firebase’i ortak kullanmak isterseniz uygulamanız içerisinde Notification Service Extension classına aşağıdaki kodu eklemeniz yeterli.

Code Block
import UserNotifications
import Euromsg
import FirebaseMessaging
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)
        if (self.bestAttemptContent != nil) {
            var userInfo = self.bestAttemptContent?.userInfo;
            let emPushSp = userInfo?["emPushSp"];
            if (emPushSp != nil) {
                print("--RelatedDigital Push")
                userInfo?.removeValue(forKey: "fcm_options")
                self.bestAttemptContent?.userInfo = userInfo!
                Euromsg.configure(appAlias: "EuromsgIOSTestDev", launchOptions: nil, enableLog: true, appGroupsKey: "group.com.relateddigital.EuromsgExample.relateddigital", deliveredBadge: false)
                Euromsg.didReceive(bestAttemptContent, withContentHandler: contentHandler)
            } else {
                print("--Firebase Push")
                Messaging.serviceExtension().populateNotificationContent(self.bestAttemptContent!, withContentHandler: contentHandler)
            }
        }
    }
    override func serviceExtensionTimeWillExpire() {
        guard let contentHandler = self.contentHandler else {
            return;
        }
        guard let bestAttemptContent = self.bestAttemptContent else {
            return;
        }
        contentHandler(bestAttemptContent)
    }
}