在Swift 2 iOS 9中解析推送通知

在Swift 2 iOS 9中解析推送通知,swift,parse-platform,apple-push-notifications,swift2,ios9,Swift,Parse Platform,Apple Push Notifications,Swift2,Ios9,我正在尝试使用Parse.com网站在我的第一个应用程序中显示推送通知,我遵循了教程和其他网站指南,当一切正常时,通知不会出现在我的设备中 Parse.com说我的证书没有问题,当我按下“测试推送通知”时,它说一切正常,但是通知没有出现在我的设备中 它显示“0推送已发送” 这是我的代码(AppDelegate):我必须做一些更改,因为我使用的是Swift 2,并且关于代码的解析指南中存在一些错误 你知道他为什么不工作吗?我必须改变什么才能让它工作 import UIKit import Par

我正在尝试使用Parse.com网站在我的第一个应用程序中显示推送通知,我遵循了教程和其他网站指南,当一切正常时,通知不会出现在我的设备中

Parse.com说我的证书没有问题,当我按下“测试推送通知”时,它说一切正常,但是通知没有出现在我的设备中

它显示“0推送已发送”

这是我的代码(AppDelegate):我必须做一些更改,因为我使用的是Swift 2,并且关于代码的解析指南中存在一些错误

你知道他为什么不工作吗?我必须改变什么才能让它工作

import UIKit

import Parse

import Bolts

extension UIColor {
convenience init(hex: Int) {
    let r = hex / 0x10000
    let g = (hex - r*0x10000) / 0x100
    let b = hex - r*0x10000 - g*0x100
    self.init(red: CGFloat(r)/255, green: CGFloat(g)/255, blue: CGFloat(b)/255, alpha: 1)
}
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

    // Registramos la Push Notification
    if application.applicationState != UIApplicationState.Background {

        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 application.respondsToSelector("registerUserNotificationSettings:") {
        let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        //let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound
        //application.registerForRemoteNotificationTypes(types)
    }

    Parse.setApplicationId("ynwxRlK1AYrB3ib36ELpyDbWEedg9LTWarTSFI4o", clientKey: "J7v458RE9yIgmvQk5UH3IRMLsozEnoIvjWFj3t6b")

    // Change navigation bar appearance
    UINavigationBar.appearance().barTintColor = UIColor(hex: 0x00B7BB)

    UINavigationBar.appearance().tintColor = UIColor.whiteColor()

    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

    if let barFont = UIFont(name: "Avenir Next", size: 20.0) {
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(), NSFontAttributeName:barFont]
    }

    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

    return true
}

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

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

+信息:当我在我的设备中检查通知时,它会显示来自我的应用程序的信息,并且所有内容都已激活。

相信您正在使用支持推送通知的配置文件,我建议您检查端口号5223。这是传递推送通知的端口。我也有类似的问题,结果证明这个端口由于防火墙限制而被阻塞

如果您不是这样,我建议您一步一步地进行故障排除


祝你好运

相信您正在使用支持推送通知的配置文件,我建议您检查端口号5223。这是传递推送通知的端口。我也有类似的问题,结果证明这个端口由于防火墙限制而被阻塞

如果您不是这样,我建议您一步一步地进行故障排除


祝你好运

那么,
didRegisterforRemotionTificationswithDeviceToken
是否被调用?你有没有收到过设备令牌?嗨@Abhinav,我第一次启动应用程序时,它会显示一个弹出窗口,要求获得发送通知的权限。这很好,但是你上面的方法会被调用吗?你能在里面放一个日志语句并打印设备令牌吗?是的,它的名字是:
didRegisterForRemotionTificationswithDeviceToken
被调用了吗?你有没有收到过设备令牌?嗨@Abhinav,我第一次启动应用程序时,它会显示一个弹出窗口,要求获得发送通知的权限。这很好,但是你上面的方法会被调用吗?你能在里面放一份日志声明并打印设备令牌吗?是的,它的名字是:Thank@Abhinav,一些文档是Objective-C,我需要Swift 2的更多信息,因为我不知道在哪里可以找到它。非常感谢。我必须创建另一个资源调配配置文件,然后它才能正常工作!:)谢谢@Abhinav,有些文件是Objective-C,我需要Swift 2的更多信息,因为我不知道在哪里可以找到它。非常感谢。我必须创建另一个资源调配配置文件,然后它才能正常工作!:)