2014-10-22 20 views
8

tôi đang cố gắng để có được phân tích cú pháp thông báo đẩy làm việc trên ứng dụng của tôi (tất cả nhanh chóng) nhưng trong khi cố gắng thực hiện, tôi nhận được lỗi 'PFInstallation' does not have a member named 'saveInBackground'Parse Đẩy Thông báo - Lắp đặt Swift không làm việc

Đây là mã của tôi.

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

Khi tôi thay đổi currentInstallation.saveInBackground để currentInstallation.saveEvenutally(), mã biên dịch tốt ..

Nhưng khi cố gắng đăng ký thành công cho thông báo đẩy, một lỗi bật lên trong giao diện điều khiển nói Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)

tôi đã dành nhiều giờ cố gắng để tìm ra điều này, không có xúc xắc, bất kỳ trợ giúp được đánh giá cao.

Trả lời

22

Để bất kỳ ai khác có lỗi này, hãy chắc chắn rằng bạn nhập các khuôn khổ Bu lông vào Bridging Tiêu đề của bạn nộp

Không được nêu trong tài liệu crap của họ.

Điều đó khắc phục được sự cố.

Dưới đây là mã.

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

Chỉ cần thêm phần đó vào tiêu đề bắc cầu của bạn thì bạn nên làm. Cảm ơn

+0

Điều này vẫn không sửa chữa nó cho tôi: (, làm điều này + var currentInstallation: PFInstallation = PFInstallation.currentInstallation() làm việc – yoshyosh

+1

'nhập khẩu Bolts' Đó là nó –

7

PFInstallation hợp lệ chỉ có thể được khởi tạo qua [PFInstallation currentInstallation] vì các trường định danh bắt buộc chỉ đọc. (source)

Vì vậy, thay vì:

var currentInstallation: PFInstallation = PFInstallation() 

Hãy thử:

var currentInstallation = PFInstallation.currentInstallation() 
+0

Ok, điều đó không làm được gì nhiều. Vẫn có lỗi "PFInstallation" không có thành viên có tên 'saveInBackground' " –

+0

Nó nhận được deviceID tốt, chỉ cần không đăng ký bên Parse như là một cài đặt. Nó sẽ không nhận được push của –

+0

Vâng, bạn sẽ không nhận được đẩy cho đến khi bạn nhận được phương pháp lưu để làm việc. 'CurrentInstallation' có thể là một tùy chọn cho một số lý do? Tùy chọn bấm vào nó và xem nếu nó là loại 'PFInstallation? ' – Andrew

4

Chỉ cần viết import Bolts trong bạn AppDelegate.swift nộp

+3

Đây phải là câu trả lời được chấp nhận. Câu trả lời được chấp nhận hiện tại không hoạt động. – JYeh

2

Ngoài việc nhập Bu lông, tôi cố định các lỗi tương tự trong ứng dụng của tôi bằng cách thay đổi các chức năng để

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

Từ hướng dẫn Parse trên Đẩy Thông báo (trái ngược với hướng dẫn nhanh): https://parse.com/docs/ios/guide#push-notifications

Các vấn đề liên quan