Urban Airship 未在应用程序中显示警报
Urban Airship not showing alert within the app
我正在从 parse.com 迁移到城市飞艇,我快完成了,一切正常,但有一件事。当我的应用程序打开时,会发送推送通知并显示警报视图 IS NOT。如果我将应用程序放在 background 或 close 应用程序我 successfully receive 通知.
我尝试了不同的方法来让它工作,我尝试添加:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
UAirship.push().appRegisteredForRemoteNotificationsWithDeviceToken(deviceToken)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
UAirship.push().appRegisteredUserNotificationSettings()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
UAirship.push().appReceivedRemoteNotification(userInfo, applicationState: application.applicationState)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
UAirship.push().appReceivedRemoteNotification(userInfo,
applicationState:application.applicationState,
fetchCompletionHandler:completionHandler)
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
UAirship.push().appReceivedActionWithIdentifier(identifier!,
notification: userInfo,
applicationState: application.applicationState,
completionHandler: completionHandler)
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
UAirship.push().appReceivedActionWithIdentifier(identifier!,
notification: userInfo,
responseInfo: responseInfo,
applicationState: application.applicationState,
completionHandler: completionHandler)
}
并将 UAConfig 更改为 automatic setup disabled:
let config: UAConfig = UAConfig.defaultConfig()
config.automaticSetupEnabled = false
UAirship.takeOff(config)
我还向我的 AppDelegate 添加了这个:
class AppDelegate: UIResponder, UIApplicationDelegate, UAPushNotificationDelegate {
和放 这个:
UAirship.push().userNotificationTypes = [.Alert, .Badge, .Sound]
UAirship.push().pushNotificationDelegate = self
但是什么都没有有用,我真的很沮丧,因为我不能让它工作,对我来说,城市飞艇文档,这个事情不清楚
如果我没记错的话,默认情况下它应该可以工作,而无需执行所有这些操作,但事实并非如此。
我希望有人能帮助我,这是我没有所有修改的完整代码:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Populate AirshipConfig.plist with your app's info from
// https://go.urbanairship.com
// or set runtime properties here.
let config: UAConfig = UAConfig.defaultConfig()
UAirship.takeOff(config)
UAirship.push().userPushNotificationsEnabled = true
// Clear badge
UAirship.push().resetBadge()
return true
}[...]}
我正在使用 Swift 2、XCode 7.2.1 和 iOS8,以及 Urban AirShip 6。4.x
谢谢
如果您想在收到前台通知时触发警报显示,您需要实施 UAPushNotificationDelegate 并在那里处理警报。在收到前台通知时显示警报不是 Urban Airship SDK 中的默认行为。
推送通知委托
创建一个 class 实现 UAPushNotificationDelegate 并包含可选的 receivedForegroundNotification 方法或 displayNotificationAlert 方法。
class PushNotificationDelegate : NSObject, UAPushNotificationDelegate {
func receivedForegroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
// Called when the app receives a foreground notification. Includes the notification dictionary.
// Call the completion handler
completionHandler(UIBackgroundFetchResult.NoData)
}
func displayNotificationAlert(alertMessage: String) {
// Called when an alert notification is received in the foreground. Includes a simple string to be displayed as an alert.
}
}
设置委托
UAirship.push().pushNotificationDelegate = customPushDelegate
您可以查看 Urban Airship 的 documentation 推送通知代表。
我正在从 parse.com 迁移到城市飞艇,我快完成了,一切正常,但有一件事。当我的应用程序打开时,会发送推送通知并显示警报视图 IS NOT。如果我将应用程序放在 background 或 close 应用程序我 successfully receive 通知.
我尝试了不同的方法来让它工作,我尝试添加:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
UAirship.push().appRegisteredForRemoteNotificationsWithDeviceToken(deviceToken)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
UAirship.push().appRegisteredUserNotificationSettings()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
UAirship.push().appReceivedRemoteNotification(userInfo, applicationState: application.applicationState)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
UAirship.push().appReceivedRemoteNotification(userInfo,
applicationState:application.applicationState,
fetchCompletionHandler:completionHandler)
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
UAirship.push().appReceivedActionWithIdentifier(identifier!,
notification: userInfo,
applicationState: application.applicationState,
completionHandler: completionHandler)
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
UAirship.push().appReceivedActionWithIdentifier(identifier!,
notification: userInfo,
responseInfo: responseInfo,
applicationState: application.applicationState,
completionHandler: completionHandler)
}
并将 UAConfig 更改为 automatic setup disabled:
let config: UAConfig = UAConfig.defaultConfig()
config.automaticSetupEnabled = false
UAirship.takeOff(config)
我还向我的 AppDelegate 添加了这个:
class AppDelegate: UIResponder, UIApplicationDelegate, UAPushNotificationDelegate {
和放 这个:
UAirship.push().userNotificationTypes = [.Alert, .Badge, .Sound]
UAirship.push().pushNotificationDelegate = self
但是什么都没有有用,我真的很沮丧,因为我不能让它工作,对我来说,城市飞艇文档,这个事情不清楚
如果我没记错的话,默认情况下它应该可以工作,而无需执行所有这些操作,但事实并非如此。
我希望有人能帮助我,这是我没有所有修改的完整代码:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Populate AirshipConfig.plist with your app's info from
// https://go.urbanairship.com
// or set runtime properties here.
let config: UAConfig = UAConfig.defaultConfig()
UAirship.takeOff(config)
UAirship.push().userPushNotificationsEnabled = true
// Clear badge
UAirship.push().resetBadge()
return true
}[...]}
我正在使用 Swift 2、XCode 7.2.1 和 iOS8,以及 Urban AirShip 6。4.x
谢谢
如果您想在收到前台通知时触发警报显示,您需要实施 UAPushNotificationDelegate 并在那里处理警报。在收到前台通知时显示警报不是 Urban Airship SDK 中的默认行为。
推送通知委托
创建一个 class 实现 UAPushNotificationDelegate 并包含可选的 receivedForegroundNotification 方法或 displayNotificationAlert 方法。
class PushNotificationDelegate : NSObject, UAPushNotificationDelegate {
func receivedForegroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
// Called when the app receives a foreground notification. Includes the notification dictionary.
// Call the completion handler
completionHandler(UIBackgroundFetchResult.NoData)
}
func displayNotificationAlert(alertMessage: String) {
// Called when an alert notification is received in the foreground. Includes a simple string to be displayed as an alert.
}
}
设置委托
UAirship.push().pushNotificationDelegate = customPushDelegate
您可以查看 Urban Airship 的 documentation 推送通知代表。