Swi*_*yJD 1 push-notification apple-push-notifications ios appdelegate swift
我已经设置推送通知并在appdelegate中工作,但是一旦应用程序打开,我就不会让它们启动,我希望它们在用户注册应用程序后在单独的"允许推送通知"视图控制器上启动.我尝试appDelegate通过这样做来引用:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
Run Code Online (Sandbox Code Playgroud)
我有一个registerForPushNotifications功能appDelegate:
func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
Run Code Online (Sandbox Code Playgroud)
从didFinishLaunchingWithOptions函数内部调用时有效,AppDelegate但是当我尝试在我的视图控制器上调用该函数时,我没有任何东西可以传递给函数的应用程序部分,所以我最终得到一个错误.
@IBAction func yesButtonPressed(sender: AnyObject) {
appDelegate.registerForPushNotifications(application)
performSegueWithIdentifier("pushToHomeSegue", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
你确定你没有任何东西可以传递给你application吗?
appDelegate.registerForPushNotifications(UIApplication.sharedApplication())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1191 次 |
| 最近记录: |