Ios 城市飞艇在应用程序内未显示警报

Ios 城市飞艇在应用程序内未显示警报,ios,push,uialertview,urbanairship.com,Ios,Push,Uialertview,Urbanairship.com,我正在从parse.com迁移到urban airship,我几乎完成了,一切都正常,但有一件事。当我的应用程序处于打开状态并发送推送通知时,不会显示警报视图。如果我将应用程序置于后台或关闭,则应用程序将成功接收通知 我尝试了不同的方法来实现它,我尝试添加: func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

我正在从parse.com迁移到urban airship,我几乎完成了,一切都正常,但有一件事。当我的应用程序处于打开状态并发送推送通知时,不会显示警报视图。如果我将应用程序置于后台关闭,则应用程序将成功接收通知

我尝试了不同的方法来实现它,我尝试添加:

    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更改为自动设置禁用

        let config: UAConfig = UAConfig.defaultConfig()
    config.automaticSetupEnabled = false
    UAirship.takeOff(config)
        UAirship.push().userNotificationTypes = [.Alert, .Badge, .Sound]
    UAirship.push().pushNotificationDelegate = self
我还向我的AppDelegate添加了以下内容:

class AppDelegate: UIResponder, UIApplicationDelegate, UAPushNotificationDelegate {
推杆
这个

        let config: UAConfig = UAConfig.defaultConfig()
    config.automaticSetupEnabled = false
    UAirship.takeOff(config)
        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以及城市飞艇6.4.x


谢谢

如果您希望在收到前台通知时触发警报显示,则需要在那里执行并处理警报。在城市飞艇SDK中,收到前台通知时显示警报不是默认行为

推送通知委托

UAirship.push().pushNotificationDelegate = customPushDelegate
创建一个类,该类实现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

您可以查看城市飞艇上的推送通知代理。

我遗漏了一些其他内容,因为它仍然不工作:/您如何配置推送通知代理?必须在
UAirship.takeOff(config)
之后设置,如下所示。我正在iPhone上接收推送,但未显示警报。我必须在这些方法中创建警报吗?没错。您需要在receivedForegroundNotification或displayNotificationAlert方法中创建警报视图。如果我想添加横幅而不是警报,该怎么办?