ios – 收到推送通知时不显示横幅振动设备

当我发送推送通知时,我收到设备上的通知,但它没有在iPhone的锁定屏幕或通知中心显示为横幅.我在iPhone上安装了iOS 9.

以下是我的代码.

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

    return true
}

func registerForPushNotifications(application: UIApplication)
{

    let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil)

    UIApplication.sharedApplication().registerUserNotificationSettings(settings)

    UIApplication.sharedApplication().registerForRemoteNotifications()

}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
    print("DEVICE TOKEN = \(deviceToken)")

    let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
    var tokenString = ""

    for i in 0..<deviceToken.length
    {
        tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
    }

    print("tokenString: \(tokenString)")
    strDeviceToken = tokenString
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)
{
    print("Error = \(error)")
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
        print(userInfo)
    }

最佳答案 最后我解决了这个问题.他们在PHP代码上的问题不在iOS代码中.在PHP代码中,他们缺少警报关键字在aps数组中,为什么设备只在接收通知时振动.

点赞