不显示横幅仅在收到推送通知时振动设备
Not Showing banner only vibrate device when push notification received
当我发送推送通知时,我在设备上收到通知,但它没有在 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)
}
确保您的应用程序处于后台或已关闭,否则推送通知消息将不会在屏幕上显示。当应用程序 运行 在前台时,iOS 直接将推送通知消息传递给宿主应用程序,而不在主屏幕或通知屏幕上显示。
When your app is frontmost, UIKit delivers local and remote
notifications directly to your app delegate object without displaying
any system UI. UIKit calls the
application:didReceiveLocalNotification: method for incoming local
notifications and the
application:didReceiveRemoteNotification:fetchCompletionHandler:
method for incoming remote notifications. Use the provided
notification dictionary to update your app accordingly. Because your
app is running, you can incorporate the notification data quietly or
update your user interface and let the user know that new information
is available.
我终于解决了这个问题。他们关于 php 代码的问题不在 iOS 代码中。在 php 代码中,它们缺少 alert aps 数组中的关键字,这就是为什么设备仅在收到通知时才振动。
当我发送推送通知时,我在设备上收到通知,但它没有在 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)
}
确保您的应用程序处于后台或已关闭,否则推送通知消息将不会在屏幕上显示。当应用程序 运行 在前台时,iOS 直接将推送通知消息传递给宿主应用程序,而不在主屏幕或通知屏幕上显示。
When your app is frontmost, UIKit delivers local and remote notifications directly to your app delegate object without displaying any system UI. UIKit calls the application:didReceiveLocalNotification: method for incoming local notifications and the application:didReceiveRemoteNotification:fetchCompletionHandler: method for incoming remote notifications. Use the provided notification dictionary to update your app accordingly. Because your app is running, you can incorporate the notification data quietly or update your user interface and let the user know that new information is available.
我终于解决了这个问题。他们关于 php 代码的问题不在 iOS 代码中。在 php 代码中,它们缺少 alert aps 数组中的关键字,这就是为什么设备仅在收到通知时才振动。