gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:39 26 4
gpt4 key购买 nike

当我发送推送通知时,我在设备上收到通知,但它没有在 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 数组中的 alert 关键字,这就是为什么设备仅在收到通知时才振动。

关于ios - 不显示横幅仅在收到推送通知时振动设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38720800/

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