首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析推送通知-快速安装不起作用

解析推送通知-快速安装不起作用
EN

Stack Overflow用户
提问于 2014-10-22 05:37:53
回答 4查看 4.4K关注 0票数 8

我正在尝试让Parse通知在我的应用程序上工作(都是快速的),但是在尝试实现时,我得到了错误'PFInstallation' does not have a member named 'saveInBackground'

这是我的密码。

代码语言:javascript
复制
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.saveInBackground改为currentInstallation.saveEvenutally()时,代码编译得很好。

但是,当尝试成功地注册推送通知时,控制台中会弹出一个错误,上面写着Error: deviceType must be specified in this operation (Code: 135, Version: 1.4.2)

我花了好几个小时试图弄清楚,没有骰子,任何帮助都是感激的。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-10-24 07:53:44

对于其他有此错误的人,请确保将Bolts框架导入桥接头文件中。

在他们的垃圾文件里没有提到。

这就解决了问题。

下面是密码。

代码语言:javascript
复制
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>

只要把这个加到你的桥接头上,你就可以走了。谢谢

票数 22
EN

Stack Overflow用户

发布于 2014-10-22 05:48:46

有效的PFInstallation只能通过PFInstallation currentInstallation实例化,因为所需的标识符字段是只读的。(来源)

因此,与其:

代码语言:javascript
复制
var currentInstallation: PFInstallation = PFInstallation()

尝试:

代码语言:javascript
复制
var currentInstallation = PFInstallation.currentInstallation()
票数 7
EN

Stack Overflow用户

发布于 2015-08-06 12:41:31

只需在您的import Bolts文件中写入AppDelegate.swift

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26500928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档