Push bildirim izni istemek ve izine onay verildikten sonra token'ı yakalamak için alttaki satırları çalıştırın.
Kullanıcıdan push bildirimleri göndermek için izin istemek yerine, uygulamanız geçici yetkilendirme isteyebilir.
Geçici yetkilendirmeyi etkinleştirmek içinrequestPermission
methodu içerisineisProvisional
parametresinitrue
olarak ayarlamalısınız(Provisional push yalnızca iOS platformunda desteklenmektedir)
String token = '-'; void _getTokenCallback(RDTokenResponseModel result) { if(result != null && result.deviceToken != null && result.deviceToken.isNotEmpty) { setState(() { token = result.deviceToken; }); } else { setState(() { token = 'Token not retrieved'; }); } } Future<void> requestPermission() async { await relatedDigitalPlugin.requestPermission(_getTokenCallback, isProvisional: true); }
Rich Push Notifications
Resimli, butonlu ve rozetli bildirimler alabilmek için aşağıdaki adımları takip ediniz.
Xcode'da yeni bir Notification Service Extension hedefi ekleyin ve bunu NotificationService olarak adlandırın.
Pod dosyanıza aşağıdaki bölümü ekleyin ve ardından
pod install
çalıştırın.target 'NotificationService' do use_frameworks! pod 'Euromsg' end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No' end end end
NotificationService hedefinin dağıtım hedefini iOS 11 olarak ayarlayın.
NotificationService.swift dosya içeriğini aşağıdaki kodla değiştirin.
import UserNotifications import Euromsg 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) Euromsg.didReceive(bestAttemptContent, withContentHandler: contentHandler) } override func 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. if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { Euromsg.didReceive(bestAttemptContent, withContentHandler: contentHandler) } } }
Carousel Push Notifications
Carousel push bildirimleri alabilmek için aşağıdaki adımları izleyin.
Xcode'da yeni bir Notification Content Extension hedefi ekleyin ve bunu NotificationContent olarak adlandırın.
Pod dosyanıza aşağıdaki bölümü ekleyin ve ardından
pod install
çalıştırın.target 'NotificationContent' do use_frameworks! pod 'Euromsg' end
NotificationContent hedefinin dağıtım hedefini iOS 11 olarak ayarlayın.
MainInterface.storyboard ve NotificationContent.swift dosyalarını silin. Ardından, NotificationContent klasörü altında EMNotificationViewController.swift adlı bir Swift dosyası oluşturun.
EMNotificationViewController.Swift dosya içeriğini aşağıdaki kodla değiştirin.
import UIKit import UserNotifications import UserNotificationsUI import Euromsg @available(iOS 10.0, *) @objc(EMNotificationViewController) class EMNotificationViewController: UIViewController, UNNotificationContentExtension { let appUrl = URL(string: "euromsgExample://") let carouselView = EMNotificationCarousel.initView() var completion: ((_ url: URL?, _ userInfo: [AnyHashable: Any]?) -> Void)? func didReceive(_ notification: UNNotification) { carouselView.didReceive(notification) } func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) { carouselView.didReceive(response, completionHandler: completion) } override func loadView() { completion = { [weak self] url, userInfo in if let url = url { self?.extensionContext?.open(url) if url.scheme != self?.appUrl?.scheme, let userInfo = userInfo { Euromsg.handlePush(pushDictionary: userInfo) } } else if let url = self?.appUrl { self?.extensionContext?.open(url) } } carouselView.completion = completion //Add if you want to track which element has been selected carouselView.delegate = self self.view = carouselView } } /** Add if you want to track which carousel element has been selected */ extension EMNotificationViewController: CarouselDelegate { func selectedItem(_ element: EMMessage.Element) { //Add your work... print("Selected element is => \(element)") } }
NotificationContent/Info.plist
'inize aşağıdaki bölümü ekleyin.<key>NSExtension</key> <dict> <key>NSExtensionAttributes</key> <dict> <key>UNNotificationExtensionCategory</key> <string>carousel</string> <key>UNNotificationExtensionDefaultContentHidden</key> <false /> <key>UNNotificationExtensionInitialContentSizeRatio</key> <real>1</real> <key>UNNotificationExtensionUserInteractionEnabled</key> <true /> </dict> <key>NSExtensionPointIdentifier</key> <string>com.apple.usernotifications.content-extension</string> <key>NSExtensionPrincipalClass</key> <string>NotificationContent.EMNotificationViewController</string> </dict>
Set Push Permit
Uygulama için push bildirimlerini etkinleştirmek veya devre dışı bırakmak için yalnızca setNotificationPermission
yöntemini çağırabilirsiniz.
relatedDigitalPlugin.setNotificationPermission(true);