2014-10-22 8 views
8

मैं पार्स पाने के लिए मेरे एप्लिकेशन (सभी तेज) पर काम कर रहा पुश सूचनाएं कोशिश कर रहा हूँ, लेकिन लागू करने की कोशिश करते हुए, मैं त्रुटि 'PFInstallation' does not have a member named 'saveInBackground'पार्स पुश सूचनाएं - स्विफ्ट स्थापना काम नहीं

मिल यहाँ मेरी कोड है।

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) 
} 

जब मैं बदल currentInstallation.saveInBackgroundcurrentInstallation.saveEvenutally() करने के लिए, कोड ठीक संकलित ..

लेकिन जब सफलतापूर्वक पुश नोटिफिकेशन के लिए साइन अप करने की कोशिश कर, एक त्रुटि कंसोल कह Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)

मैं में पॉप अप होता है इसने इसे समझने के लिए घंटों बिताए हैं, कोई पासा नहीं, किसी भी मदद की सराहना की है।

उत्तर

22
किसी और ने इस त्रुटि है करने के लिए

, सुनिश्चित करें कि आप अपने ब्रिजिंग हैडर में बोल्ट ढांचे आयात फ़ाइल

बनाने

जो उनके बकवास दस्तावेज़ों में उल्लिखित नहीं है।

यह समस्या को हल करता है।

नीचे कोड है।

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

बस अपने ब्रिजिंग हैडर में नहीं जोड़ तो आप जाने के लिए अच्छे हैं। धन्यवाद

+0

यह अभी भी मेरे लिए इसे ठीक नहीं करता है :(, यह + var currentInstallation: PFInstallation = PFInstallation कर रहा है।currentInstallation() ने – yoshyosh

+1

आयात किया बोल्ट ' यह –

7

एक वैध PFInstallation केवल [PFInstallation currentInstallation] क्योंकि आवश्यक पहचानकर्ता क्षेत्रों केवल पढ़ने के लिए कर रहे हैं के माध्यम से instantiated जा सकता है। (source)

तो बजाय:

var currentInstallation: PFInstallation = PFInstallation() 

प्रयास करें:

var currentInstallation = PFInstallation.currentInstallation() 
+0

ठीक है, उसने बहुत कुछ नहीं किया। अभी भी त्रुटि है "'PFInstallation' में 'saveInBackground' नामक कोई सदस्य नहीं है" –

+0

यह डिवाइस आईडी ठीक है, बस एक इंस्टॉलेशन के रूप में पार्स की तरफ पंजीकरण नहीं करेगा। इसे पुश का –

+0

प्राप्त नहीं होगा ठीक है जब तक आपको काम करने के लिए सहेजने की विधि नहीं मिल जाती तब तक आपको धक्का नहीं मिलेगा। क्या 'मौजूदा स्थापना' शायद किसी कारण से वैकल्पिक है? विकल्प-क्लिक करें और देखें कि यह 'PFInstallation प्रकार' है? – Andrew

4

बस लिखना आप में import Bolts AppDelegate.swift

+3

यह स्वीकार्य उत्तर होना चाहिए। वर्तमान स्वीकृत उत्तर काम नहीं करता है। – JYeh

2

फ़ाइल बोल्ट आयात करने के अलावा, मैं

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() 
} 

के समारोह को बदलने के पुश पर पार्स गाइड से द्वारा मेरे एप्लिकेशन में एक ही त्रुटि ठीक अधिसूचनाएं (क्विकस्टार्ट गाइड के विपरीत): https://parse.com/docs/ios/guide#push-notifications

संबंधित मुद्दे