2015-09-28 1 views
0

Я интегрирую уведомления Parse Push в приложение и попал в конверсии Swift 2.0. Кодекса:Интеграция оповещений о переносе паролей в проект Xcode 7 (Swift)

if application.respondsToSelector("registerUserNotificationSettings:") { 
      let userNotificationTypes: UIUserNotificationType = [.Alert, .Badge, .Sound] 
      let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil) 
      application.registerUserNotificationSettings(settings) 
      application.registerForRemoteNotifications() 
     } else { 
      let types: UIUserNotificationType = [.Badge, .Alert, .Sound] 
      application.registerForRemoteNotificationTypes(types) 
     } 

Xcode жалуется, что «Невозможно преобразовать значение типа„UIUserNotificationType“к ожидаемому типу аргумента„UIRemoteNotificationType“

ответ

2

попробовать этот код ...

приложение delegate.swift

import UIKit 
import Parse 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 

//-------------------------------------- 
// MARK: - UIApplicationDelegate 
//-------------------------------------- 

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    Parse.setApplicationId("APIKEYHERE", clientKey: "CLIENTKEYHERE") 

    let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] 
    let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil) 

    application.registerUserNotificationSettings(settings) 
    application.registerForRemoteNotifications() 

    return true 
} 

//-------------------------------------- 
// MARK: Push Notifications 
//-------------------------------------- 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
    let installation = PFInstallation.currentInstallation() 
    installation.setDeviceTokenFromData(deviceToken) 
    installation.saveInBackground() 

    PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in 
     if succeeded { 
      print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n"); 
     } else { 
      print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error) 
     } 
    } 
} 

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    if error.code == 3010 { 
     print("Push notifications are not supported in the iOS Simulator.\n") 
    } else { 
     print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error) 
    } 
} 

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    PFPush.handlePush(userInfo) 
    if application.applicationState == UIApplicationState.Inactive { 
     PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo) 
    } 
    } 

} 
3

Попробуйте следующий код, хотя Xcode все еще показывает предупреждения, что UIRemoteNotificationType осуждался в прошивке 8,0

let types : UIRemoteNotificationType = [.Badge, .Alert, .Sound] 
application.registerForRemoteNotificationTypes(types) 
6

Попробуйте следующий код, так как UIRemoteNotification является устаревшим, использовать registerUserNotificationSettigns, чтобы установить параметры уведомлений. Но помните, чтобы настроить push уведомления в центре участника Apple и при синтаксическом анализе, чтобы он мог работать. Вы можете следовать этому руководству с шага 1 до шага 4, это здорово. https://www.parse.com/tutorials/ios-push-notifications

if application.respondsToSelector("registerUserNotificationSettings:") { 
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 
    application.registerUserNotificationSettings(settings) 
    application.registerForRemoteNotifications() 
} 
Смежные вопросы