Я следую шаг за шагом microssoft, чтобы использовать AppCenterPush , однако при попытке вставить "MSPushDelegate.setDelegate (self)" XCode возвращает мне следующую ошибку "Тип" MSPushDelegate "не имеет члена"setDelegate».Я думаю, что не могу зарегистрировать устройство или получить уведомление, потому что не могу связать MSPushDelegate.
Мой текущий код:
import UIKit
import UserNotifications
import AppCenter
import AppCenterAnalytics
import AppCenterCrashes
import AppCenterPush
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MSPushDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Clean notifications
application.applicationIconBadgeNumber = 0
application.cancelAllLocalNotifications()
//enable notification (used for local notifications)
let notificationSettings = UIUserNotificationSettings(types: [.alert, .sound, .badge], categories: nil)
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
UIApplication.shared.registerForRemoteNotifications()
// Notification by AppCenterPush
MSPush.setDelegate(self) // this line show the error: "Type 'MSPush' has no member 'setDelegate'"
MSAppCenter.setEnabled(true)
MSAppCenter.start("{MyAppSecret}", withServices: [
MSAnalytics.self,
MSCrashes.self,
MSPush.self
])
return true
}
Мой код для отображения уведомления:
func push(_ push: MSPush!, didReceive pushNotification: MSPushNotification!) {
print("Working")
let title: String = pushNotification.title ?? ""
var message: String = pushNotification.message ?? ""
var customData: String = ""
for item in pushNotification.customData {
customData = ((customData.isEmpty) ? "" : "\(customData), ") + "\(item.key): \(item.value)"
}
if (UIApplication.shared.applicationState == .background) {
NSLog("Notification received in background, title: \"\(title)\", message: \"\(message)\", custom data: \"\(customData)\"");
} else {
message = message + ((customData.isEmpty) ? "" : "\n\(customData)")
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
// Show the alert controller.
self.window?.rootViewController?.present(alertController, animated: true)
}
}