相关疑难解决方法(0)

在后台使用didReceiveRemoteNotification

这样的问题已被多次询问,但我有一些特定的情况正在发生.

当我的应用程序处于活动状态并且我收到PUSH消息时,我成功地能够解析自定义有效负载等.

但是当我的应用程序在后台并且PUSH到达时,用户必须单击"查看/打开"按钮才能获得didReceiveRemoteNotification被叫,然后didFinishLaunchingWithOptions被调用.

我需要让我的应用程序决定是否必须在后台提示用户使用UIAlert,或者根据某些本地设置禁止推送消息.

任何帮助,将不胜感激,

iphone apple-push-notifications ios4

52
推荐指数
4
解决办法
7万
查看次数

如何在点击通知时处理Swift 3中的启动选项?获得语法问题

我正在尝试处理启动选项并在点击我在swift 3中收到的远程通知时打开一个特定的视图控制器.我已经看到类似的问题,例如这里,但没有新的swift 3实现.我看到了一个类似的问题(和)在AppDelegate.swift中我在didFinishLaunchingWithOptions中有以下内容:

    var localNotif = (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as! String)
if localNotif {
    var itemName = (localNotif.userInfo!["aps"] as! String)
    print("Custom: \(itemName)")
}
else {
    print("//////////////////////////")
}
Run Code Online (Sandbox Code Playgroud)

但是Xcode给了我这个错误:

Type '[NSObject: AnyObject]?' has no subscript members
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

   if let launchOptions = launchOptions {
        var notificationPayload: NSDictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary!

    }
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error: ambiguous reference to member 'subscript'
Run Code Online (Sandbox Code Playgroud)

我有类似的错误,无论我以前使用类似的代码通过键从字典中获取值,我不得不替换代码,基本上安全地首先解开字典.但这似乎不适用于此.任何帮助,将不胜感激.谢谢.

ios firebase swift firebase-cloud-messaging firebase-notifications

17
推荐指数
3
解决办法
2万
查看次数

在Swift 3中收到推送通知时如何打开特定的视图控制器

当应用程序未完全打开时,当我点击推送通知警报时,我遇到了特定的视图控制器无法移动的问题。

这是我的代码:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    /*

    fetch and add push notification data

     */
    goAnotherVC()
}

func goAnotherVC() {
    if (application.applicationState == UIApplicationState.active) {
        /* active stage is working */ 
    } else if (application.applicationState == UIApplicationState.inactive || application.applicationState == UIApplicationState.background) {
        if (type == "1" || type == "2") {
            let storyboard: UIStoryboard = UIStoryboard(name: "MyAppointments", bundle: nil)
            let apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationDetailViewController") as! NotificationDetailViewController
            let navigationController = UINavigationController.init(rootViewController: …
Run Code Online (Sandbox Code Playgroud)

ios swift3

3
推荐指数
2
解决办法
1万
查看次数