2016-02-22 56 views
1

我正在从parse.com迁移到城市飞艇,我差不多完成了所有工作,但一件事。当我的应用程序处于打开状态并发送推送通知时,将显示警报视图不是。如果我把应用程序的背景接近的应用程序,我成功收到通知城市飞艇没有在应用程序内显示警报

我必须尝试不同的东西,使其工作,我尝试加入:

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) 

我也加到我的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 
}[...]} 

我用斯威夫特2时,Xcode 7.2.1和iOS8上,与城市飞艇6.4.x

感谢

回答

2

如果你想触发警报显示当接收前景通知,你需要实现UAPushNotificationDelegate和处理警报那里。在收到前台通知时呈现警报并非Urban Airship SDK中的默认行为。

推送通知委托

创建一类实现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 

您可以查看城市飞艇documentation的推送通知委托。

+0

我错过了其他的东西,因为它仍然不能正常工作:/ – Lucas

+0

你如何配置推送通知代理?它必须在'UAirship.takeOff(config)'之后设置。 – gatlinhebert

+0

就是这样。我在iPhone上收到了推送,但没有显示提醒。我必须在这些方法中创建一个警报吗? – Lucas