gpt4 book ai didi

ios - 目前尝试使用 Xcode 7.1 将 Parse 推送交织到我的 swift 应用程序中

转载 作者:行者123 更新时间:2023-11-30 13:46:27 24 4
gpt4 key购买 nike

因此,我在尝试让 Parse Push 与我的应用程序配合使用时遇到了问题。这是我为使其发挥作用而所做的一系列事情。

  • 我已撤销并重新颁发所有证书
  • 我已将最新证书重新安装到推送设置下的解析站点
  • 我已在 Xcode 上删除并重新安装了我的 APP ID

我对此很陌生,所以我不知道从哪里开始,我可以让应用程序出现在我的手机上,它可以让我做我的事件和事情,但是当我去推送解析站点时它不会让我做任何没有注册设备的事情,所以我不确定我的代码是否不正确。

任何帮助都会很棒。

谢谢

PS 我的解析代码位于我刚刚出于发布目的而删除的实际代码中。

这是我在 AppDelegate.swift 文件中当前的代码

导入UIKit导入解析

@UIApplicationMainAppDelegate 类:UIResponder、UIApplicationDelegate {

var window: UIWindow?

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

// Set App ID
Parse.setApplicationId("Your Id Here", clientKey: "Your Key Here")



UIApplication.sharedApplication().registerForRemoteNotifications(); let settings = UIUserNotificationSettings(forTypes: [.Badge, .Alert, .Sound], categories: nil); UIApplication.sharedApplication().registerUserNotificationSettings(settings); UIApplication.sharedApplication().registerForRemoteNotifications()


UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated:true)

return true

}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.channels = ["global"]
installation.saveInBackground()
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
}

最佳答案

tl;博士您可以尝试此获取一些信息 iOS Swift PushParse Push QuickStart

长部分

通过在应用程序中添加以下内容,让您的应用程序注册远程通知:didFinishLaunchingWithOptions: 函数(如果您还没有):

    import parse


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

Parse.setApplicationId("YOURS",
clientKey: "Yours")

// Register for Push Notitications
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 pushPayload = false
if let options = launchOptions {
pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
}
if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}
if #available(iOS 8.0, *) {
let types: UIUserNotificationType = [.Alert, .Badge, .Sound]
let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
}

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

}

如果所有这些都在您的 appdelegate.swift 中并且不起作用,那么您的证书很可能有问题。

关于ios - 目前尝试使用 Xcode 7.1 将 Parse 推送交织到我的 swift 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34860475/

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