gpt4 book ai didi

iOS swift 解析推送通知,推送发送 0

转载 作者:行者123 更新时间:2023-11-29 01:41:43 24 4
gpt4 key购买 nike

设备在安装类中正确注册(我猜),当我从解析网站发送推送通知时,状态为绿色勾号但发送的推送为 0,这是我的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.e

Parse.enableLocalDatastore()

// Initialize Parse.
Parse.setApplicationId("xxxxxx",
clientKey: "xxxxxx")


// [Optional] Track statistics around application opens.
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

var defaultACL = PFACL()
defaultACL.setPublicWriteAccess(true)
defaultACL.setPublicReadAccess(true)
PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true)


let userNotificationTypes = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound);

let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()

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 oldPushHandlerOnly = !self.respondsToSelector(Selector("application:didReceiveRemoteNotification:fetchCompletionHandler:"))
let noPushPayload: AnyObject? = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey]
if oldPushHandlerOnly || noPushPayload != nil {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}

return true
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if application.applicationState == .Inactive {
// The application was just brought from the background to the foreground,
// so we consider the app as having been "opened by a push notification."
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if application.applicationState == .Inactive {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}

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

当用户注册时:

 let installation = PFInstallation.currentInstallation()
installation["user"] = PFUser.currentUser()
installation["username"] = self.userName.text.lowercaseString
installation.saveInBackground()

发送推送:

let pushQuery = PFInstallation.query()
pushQuery!.whereKey("username", equalTo:"\(self.childName)") // Set channel

// Send push notification to query
let push = PFPush()
push.setQuery(pushQuery) // Set our Installation query
push.setMessage("\(self.parentName) adopted you, you earned $\(self.configureText(10 * childValue / 100)) !")

push.sendPushInBackground()

最佳答案

你能通过 Parse 网站发送推送通知吗?如果不是,那么您缺少一些证书。

假设 self.childname 包含正确的收件人用户名,这一切看起来都不错。您确定启用客户端推送了吗?

默认情况下,您无法直接从移动应用程序发送推送,因此您必须启用此功能才能让您的代码正常工作。 Parse iOS Push Notifications Tutorial

关于iOS swift 解析推送通知,推送发送 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32320718/

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