Cách nhận mã thông báo thiết bị từ xCode 8 mới, Swift 3 trong iOS 10?Nhận mã thông báo đẩy - iOS 10, Swift 3
Đây mã để đăng ký thông báo:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
DispatchQueue.main.async {
let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
}
return true
}
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != UIUserNotificationType() {
application.registerForRemoteNotifications()
}
}
đây để có mã thông báo, nhưng tôi nhận được lỗi "Không thể gọi initializer cho loại 'UnsafePointer' với một danh sách đối số kiểu '(UnsafeRawPointer)'" :
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let chars = UnsafePointer<CChar>((deviceToken as NSData).bytes)
var token = ""
for i in 0..<deviceToken.count {
token += String(format: "%02.2hhx", arguments: [chars[i]])
}
print("Registration succeeded!")
print("Token: ", token)
}
Có ai giúp giải quyết nó không?
Cảm ơn
trùng lặp có thể xảy ra của http://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0 – Moritz
Bạn có thể đi theo liên kết này của mình trong mục tiêu C nhưng bạn có thể nhận được một số ý tưởng http://stackoverflow.com/questions/39572897/ios-10-push-notification-issue-solved –