【发布时间】:2015-01-17 14:58:48
【问题描述】:
我需要制作使用 parse 推送通知的应用程序。我正在使用这个https://parse.com/apps/quickstart#parse_push/ios/existing 和这个https://gist.github.com/sawapi/a7cee65e4ad95578044d。
代码已正确编译,我得到了
抱歉,发送推送时出错
在第一个网站上。来自 parse.com 的第一个教程完美运行。我已添加 *.p12 文件进行解析,但证书是由我的邮件而不是 ios 开发人员邮件制作的。
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId(MY_APP_ID,
clientKey: MY_APP_KEY)
PFUser.enableAutomaticUser()
if application.respondsToSelector("isRegisteredForRemoteNotifications")
{
// iOS 8 Notifications
//application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: (.Badge | .Sound | .Alert), categories: nil));
var types: UIUserNotificationType = UIUserNotificationType.Badge |
UIUserNotificationType.Alert |
UIUserNotificationType.Sound
var settings: UIUserNotificationSettings = UIUserNotificationSettings( forTypes: types, categories: nil )
application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()
return true
}
else
{
// iOS < 8 Notifications
application.registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
}
var defaultACL = PFACL()
// If you would like all objects to be private by default, remove this line.
defaultACL.setPublicReadAccess(true)
PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true)
// Override point for customization after application launch.
return true
}
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData! ) {
var currentInstallation: PFInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.save()
println("got device id! \(deviceToken)")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
}
}
【问题讨论】:
-
registerUserNotificationSettingsnotisRegisteredForRemoteNotificationsin if application.respondsToSelector("isRegisteredForRemoteNotifications") -
但是如果您在网站上遇到错误...再次检查证书... Parse.com 上有问题...
-
我会尝试为我的 iOS 开发邮件制作证书
-
下载这个项目...设置您的密钥(检查真实设备)..并检查您是否收到通知parse.com/apps/quickstart#parse_push/ios/new
-
所以我需要对代码进行任何更改还是只检查证书?我可以在哪里发送通知?
标签: ios swift parse-platform