gpt4 book ai didi

Swift 2 解析推送通知

转载 作者:行者123 更新时间:2023-11-30 14:03:34 25 4
gpt4 key购买 nike

我正在尝试在 Xcode 7.0 GM 中使用 Swift 2 进行解析推送通知。问题是它已连接但不显示推送..你知道为什么吗?预先感谢您

这是我的代码..当然我删除了我的 Parse ID,但在我的项目中有..我尝试使用 Parse 提供的代码,但我遇到了错误..所以我使用了 Github 上的一个项目,但它不是工作..

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

Parse.setApplicationId("here there is my ID of course")

PFUser.enableAutomaticUser()

let defaultACL = PFACL();

// If you would like all objects to be private by default, remove this line.
defaultACL.setPublicReadAccess(true)

PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)

if application.applicationState != UIApplicationState.Background {
// Track an app open here if we launch with a push, unless
// "content_available" was used to trigger a background push (introduced in iOS 7).
// In that case, we skip tracking here to avoid double counting the app-open.

let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var noPushPayload = false;
if let options = launchOptions {
noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
}
if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}

if application.respondsToSelector("registerUserNotificationSettings:") {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)



application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types: UIRemoteNotificationType = [UIRemoteNotificationType.Badge, UIRemoteNotificationType.Alert, UIRemoteNotificationType.Sound]
application.registerForRemoteNotificationTypes(types)
}


return true



}



//--------------------------------------
// MARK: Push Notifications
//--------------------------------------

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()

PFPush.subscribeToChannelInBackground("") { (succeeded, error) in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.", error)
}
}
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
print("Push notifications are not supported in the iOS Simulator.")
} else {
print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Inactive {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}

最佳答案

我也遇到了同样的问题,可能是由以下原因之一引起的:

1) 确保您在真实设备上运行它,而不是模拟器。模拟器不支持推送通知。

2) 在您的设备上重新安装您的应用。这解决了我的问题。当它询问时,显然允许它发送推送通知。

2) 重新创建您的证书和配置文件。单击 here看看如何。

3) 确保您的证书有效并已安装。双击下载的配置文件进行安装。

此外,您可能想创建一个用户并尝试使用该用户,而不是自动用户。

编辑:我建议您按照快速入门找到here 。我知道您会遇到错误,因此以下是修复这些错误的方法:

1) 删除let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Badge | UIUserNotificationType.Badge | UIUserNotificationType.Badge | UIUserNotificationType.Sound 并删除 let settings = UIUserNotificationSettings(forTypes: userNotificationTypes,categories: nil)。然后在删除行的位置输入 let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound],categories: nil)

2) 替换let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Alert UIRemoteNotificationType.Sound 行与 let types = UIRemoteNotificationType.Badge.union(UIRemoteNotificationType.Alert).union(UIRem‌​oteNotificationType.Sound)

关于Swift 2 解析推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32681452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com