推送通知在swift 3.0中不起作用

时间:2016-12-26 05:51:42

标签: ios swift3 apple-push-notifications

首先我们导入UserNotifications框架 我们在AppDelegate.swift class

中初始化委托方法
if #available(iOS 10.0, *){

        UNUserNotificationCenter.current().delegate = self
        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            if (granted)
            {
                UIApplication.shared.registerForRemoteNotifications()
            }
            else{
                //Do stuff if unsuccessful...
            }
            // Enable or disable features based on authorization.
        }

    }

1 个答案:

答案 0 :(得分:-1)

请检查Target > Capabilities下的“推送通知”开关:

  

将其打开