Swift iOS:如何在应用程序未运行时处理远程通知

时间:2015-05-21 02:02:11

标签: ios swift apple-push-notifications

如何在应用未运行时处理推送远程通知。目前,当远程通知进入,我的应用程序处于前台或后台时,我的代码正在正确处理远程通知。但是当应用程序未运行并且远程通知进入时,我在屏幕顶部看到一个远程横幅,当我点击它时,我的应用程序启动并消失。它似乎没有正确处理远程通知。这是iOS的行为方式,还是有办法处理它。谢谢。这是我在AppDelegate.swift中的代码。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{   
    ...
    println("..... application didFinishLaunchingWithOptions()")


    if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
    // there is a notification...do stuff...
    println("dinFInishLaunchingWithOption().. calling didREceiveRemoteNotification")
    self.application(application, didReceiveRemoteNotification: remoteNotification as [NSObject : AnyObject])

    }
    return true
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
    println("didRegisterForRemoteNotificationsWithDeviceToken")
}

fun application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)
{
    println(error)
    println(error.localizedDescription)
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
{
    println("..... application didReceiveRemoteNotification()")
}

0 个答案:

没有答案