[英]Parse iOS Swift Push Notification History
我正在使用Swift(iOS 8)解析推送通知。 问题是当应用程序关闭并且您收到多个通知时,它们将显示在通知警报中。 当我触摸其中一个通知时,它将打开我的应用程序……但是它将清除通知警报视图中的所有通知(不确定调用的内容)。 因此,所有我的推送通知都丢失了。 我需要它们,因为它们具有我的应用程序需要的特定有效负载。
因此,基本上,我需要的只是接收到的通知中的数据(而不仅仅是我打开的通知中的数据)。
我正在使用Parse建议的代码。 当应用关闭并通过推送打开时,将调用此函数。 我使用常量let = notificationPayload从推送通知中获取有效负载信息。 但是我只能一键获取数据。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Enable storing and querying data from Local Datastore.
// Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
Parse.enableLocalDatastore()
// ****************************************************************************
// Uncomment this line if you want to enable Crash Reporting
// ParseCrashReporting.enable()
//
// Uncomment and fill in with your Parse credentials:
Parse.setApplicationId("+++++", clientKey: "++++++++")
//
// If you are using Facebook, uncomment and add your FacebookAppID to your bundle's plist as
// described here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
// Uncomment the line inside ParseStartProject-Bridging-Header and the following line here:
// PFFacebookUtils.initializeFacebook()
// ****************************************************************************
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.
// Extract the notification data.
if let notificationPayload = launchOptions? [UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
// notificationPayload have payload of only one push notification.
}
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 userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound
application.registerForRemoteNotificationTypes(types)
}
return true
}
有任何相关的信息,网页,教程吗? Parse.com文档毫无用处,因为显然,当应用程序关闭时,人们只会收到一个通知。
如果您的推送通知包含重要的有效负载,则可能必须将该有效负载保存在其他位置(例如,解析云数据)。
这样,即使iOS中断了您的推送通知(或用户决定放弃它们),您的有效负载也将始终可用。
当应用程序启动时-在数据库中查找有效负载并采取相应措施。
我发现了导致通知消失的原因。 我有这段代码可以删除通知:
UIApplication.sharedApplication().applicationIconBadgeNumber = 1
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
UIApplication.sharedApplication().cancelAllLocalNotifications()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.