2016-02-18 46 views
0

我添加遠程通知與ArenaDeamons,但我得到一個錯誤(MY APP KEY是我的私有密鑰):要求允許遠程通知iOS中8

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    BDArenaConnector.initializeWithAppKey("MY APP KEY", runInSandboxEnvironment: true) 
    BDArenaConnector.getInstance().requestAuth() 
    // register for remote notifications 
    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings.settingsForTypes((UIUserNotificationTypeSound|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge), categories: nil)) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
    BDArenaConnector.getInstance().pushConnector.feedbackServiceDidFinishLaunchingWithOptions(launchOptions) 
    return true 

UINavigationBar.appearance().barTintColor = UIColor.redColor() 
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 
UIBarButtonItem.appearance().tintColor = UIColor.blueColor() 
UINavigationBar.appearance().tintColor = UIColor.whiteColor() 

    return true 
} 

ERROR1:use of unresolved identifier 'UIUserNotificationTypeBadge'
誤差2: use of unresolved identifier 'UIUserNotificationTypeSound'
誤差3:use of unresolved identifier 'UIUserNotificationTypeAlert'

我也有一些錯誤的位置:

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    print("UIApplication : didFailToRegisterForRemoteNotificationsWithError : \(error.localizedDescription)") 
    var alert: UIAlertController = UIAlertController(title: "did Fail To Register For Remote Notifications", message: error.localizedDescription(), preferredStyle: UIAlertControllerStyleAlert) 
    var okAction: UIAlertAction = UIAlertAction.actionWithTitle("Ok!", style: UIAlertActionStyleDefault, handler: { (action: UIAlertAction) in 
    }) 
    alert.addAction(okAction) 
    self.window!.rootViewController!.presentViewController(alert, animated: true, completion: nil) 
} 

ERROR1:use of unresolved identifier 'UIalertcontrollerstylealert'
誤差2:use of unresolved identifier 'UIalertactionstyledefault'

我怎樣才能解決這個問題?該應用程序在Swift 2.

回答

0

對於ios 8及以上版本,您可以使用registerUserNotificationSettings, 試試這段代碼,我沒有測試過它,但是,它會幫助您確定。

let types = UIUserNotificationType.Badge.union(UIUserNotificationType.Alert).union(UIUserNotificationType.Sound) 
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: nil)) 
UIApplication.sharedApplication().registerForRemoteNotifications() 

修正了錯誤3

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    print("UIApplication : didFailToRegisterForRemoteNotificationsWithError : \(error.localizedDescription)") 
    let alert: UIAlertController = UIAlertController(title: "did Fail To Register For Remote Notifications", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert) 
    let okAction: UIAlertAction = UIAlertAction(title: "Ok!", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction) in 
    }) 
    alert.addAction(okAction) 
    self.window!.rootViewController!.presentViewController(alert, animated: true, completion: nil) 
} 
0

您需要使用UIAlertActionStyle.DefaultUIAlertControllerStyle.Alert

0

部分固定。現在我只有2個錯誤。謝謝Prabhu.Somasundaram。

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    print("UIApplication : didFailToRegisterForRemoteNotificationsWithError : \(error.localizedDescription)") 
    let alert: UIAlertController = UIAlertController(title: "did Fail To Register For Remote Notifications", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert) 
    let okAction: UIAlertAction = UIAlertAction(title: "Ok!", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction) in 
    }) 
    alert.addAction(okAction) 
    self.window!.rootViewController!.presentViewController(alert, animated: true, completion: nil) 
} 

錯誤1:無效使用的 '()' 調用非功能類型值 '字符串'

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    BDArenaConnector.getInstance().pushConnector.feedbackServiceDidReceiveRemoteNotification(userInfo) 
    // handle push 
    BDArenaConnector.getInstance().pushConnector.handlePush(userInfo, withPresentingController: self.window!.rootViewController, withActionButtonHandler: { 

     }, withCancelButtonHandler: { 

    }) 
} 

錯誤2:可選的類型 '的UIWindow' 未展開的價值;你的意思是使用'!'要麼 '?'?

我該如何解決?