2016-09-28 19 views
18

Tôi đang tìm cách thay thế thực hiện UIUserNotificationSettings trong iOS 10.UIUserNotificationSettings không được chấp nhận trong iOS 10

Tài liệu của Apple đã đưa ra khung bên dưới để sử dụng thêm. UNNotificationSettings trong liên kết here.

Có bất cứ ai có thể giúp tôi với mẫu mã để thực hiện dưới đây sử dụng UNNotificationSettings thay vì UIUserNotificationSettings

let notificationSettings = UIUserNotificationSettings(
     forTypes: [.Badge, .Sound, .Alert], categories: nil) 
    application.registerUserNotificationSettings(notificationSettings) 
+1

Xin lỗi tôi vừa tìm thấy câu trả lời ở đây. http://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0 – Prav

Trả lời

30

Đăng ký thông báo bạn nên thực hiện mã này:

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { 
(granted, error) in 
//Parse errors and track state 
} 

này resource chứa thông tin bổ sung.

+0

Đừng quên 'application.registerForRemoteNotifications()' bên dưới mã này. –

+0

@ iOS.Wolf này chỉ cần thiết nếu bạn định có thông báo đẩy không chỉ là thông báo cục bộ. – zavtra

+0

Cũng đừng quên liên kết với UserNotifications.framework và @import UserNotifications. – NickDK

Các vấn đề liên quan