2014-10-22 22 views
8

Sto cercando di ottenere analizzare le notifiche push che lavorano sulla mia app (tutto veloce), ma durante il tentativo di implementare, ottengo l'errore 'PFInstallation' does not have a member named 'saveInBackground'Parse Notifiche Push - Installazione Swift non funziona

Ecco il mio codice.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

    Parse.setApplicationId("APP ID HIDDEN", clientKey: "CLIENT ID HIDDEN") 

    // let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 
    //let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 
    var notificationType: UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 

    var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationType, categories: nil) 
    UIApplication.sharedApplication().registerUserNotificationSettings(settings) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 

    //UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 
    // Override point for customization after application launch. 
    return true 
} 

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings!) { 
    UIApplication.sharedApplication().registerForRemoteNotifications() 

} 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 

    var currentInstallation: PFInstallation = PFInstallation() 
    currentInstallation.setDeviceTokenFromData(deviceToken) 
    currentInstallation.saveInBackground() 

    println("got device id! \(deviceToken)") 

} 


func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    println(error.localizedDescription) 
    println("could not register: \(error)") 
} 

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    PFPush.handlePush(userInfo) 
} 

quando cambio la currentInstallation.saveInBackground al currentInstallation.saveEvenutally(), il codice viene compilato bene ..

Ma quando si cerca di accedere con successo per le notifiche push, un errore si apre nella console dicendo Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)

I ho passato ore a cercare di capirlo, nessun dado, ogni aiuto è apprezzato.

risposta

22

A chiunque altro che ha questo errore, assicurarsi che si importa il quadro bulloni nella vostra Bridging intestazione del file

Quale non è descritto nei loro documenti di merda.

Questo risolve il problema.

Di seguito è riportato il codice.

#import <Parse/Parse.h> 
#import <Bolts/Bolts.h> 

Basta aggiungere questo al tuo intestazione di ponte quindi sei a posto. Grazie

+0

Questo ancora non lo aggiusta per me :(, facendo questo + var currentInstallation: PFInstallation = PFInstallation.currentInstallation() ha funzionato – yoshyosh

+1

'import Bolts' Questo è il –

7

Una PFInstallation valida può essere istanziata solo tramite [PFInstallation currentInstallation] perché i campi di identificazione richiesti sono di sola lettura. (source)

Così, invece di:

var currentInstallation: PFInstallation = PFInstallation() 

Prova:

var currentInstallation = PFInstallation.currentInstallation() 
+0

Ok, questo non ha fatto molto. Ha ancora l'errore "'PFInstallation' 'non ha un membro chiamato' saveInBackground '" –

+0

Ottiene il deviceID bene, semplicemente non si registrerà sul lato di Parse come installazione. Non riceverà il push –

+0

Bene, non si riceveranno push finché non si ottiene il metodo di salvataggio. 'CurrentInstallation' è forse un optional per qualche motivo? Opzione-clic su di esso e vedere se è di tipo 'PFInstallation?' – Andrew

4

Basta scrivere import Bolts in voi AppDelegate.swift il file

+3

Questa dovrebbe essere la risposta accettata. L'attuale risposta accettata non funziona. – JYeh

2

Oltre a importare bulloni, ho fissato lo stesso errore nel mio app cambiando la funzione per

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
    // Store the deviceToken in the current Installation and save it to Parse 
    let installation = PFInstallation.currentInstallation() 
    installation.setDeviceTokenFromData(deviceToken) 
    installation.saveInBackground() 
} 

Dalla guida Parse Push Notifiche (a differenza della guida Quickstart): https://parse.com/docs/ios/guide#push-notifications