gpt4 book ai didi

ios - 在推送通知 Swift 2 AppDelegate 上加载特定的 viewController

转载 作者:搜寻专家 更新时间:2023-11-01 06:20:46 26 4
gpt4 key购买 nike

我想打开一个特定的 View Controller (一个隐藏的,因为它只有在收到某个推送通知时才能访问(它不能通过标签栏访问))并且我已经能够做到这一点但是我面临着一个问题..

我的应用有一个名为 RootViewController 的自定义标签栏 Controller 。当您单击具有特殊值的通知时,它会显示一个警告 View ,询问用户是否要打开通知。

通知触发将特定的 View Controller 带到前面但是问题是我无法再访问标签栏了。

我不知道如何实现这一目标。

这是我在 AppDelegate.m 中的代码:

var presentedVC = self.window?.rootViewController as? UINavigationController
while (presentedVC!.navigationController != nil) {
presentedVC = presentedVC!.navigationController
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("PushNotificationView") as? NotTestViewController

destinationViewController?.url = self.url!
presentedVC?.presentViewController(destinationViewController!, animated: true, completion: nil)

})
)
alertCtrl.addAction(UIAlertAction(title: "Cancelar", style: .Destructive, handler: nil))

此代码有效但不符合预期的行为。

知道我遗漏了什么吗?

非常感谢

编辑

我已将 RAMTabBarAnimationController 更改为 TabBarController,因为 RAMTabBarAnimationController 不继承自 TabBarController。但我仍然看到相同的行为。

最佳答案

我想回答我自己的问题,因为我想也许有人面临同样的情况,我不得不感谢@Muneeba

好吧,首先你必须知道你的远程推送通知是否需要进行后台获取,这很重要,因为如果是这样,didReceiveRemoteNotification 会被调用两次(第一次是当你点击通知时警报,打开应用程序时的秒数),因此您必须意识到这一点。

在我的例子中,我没有进行后台获取,所以我的 content-available:false 标志设置为 false。

接下来要做的是将您想要的 ["key":value] 添加到通知负载中,以了解您是否要打开特定的 View Controller 。

管理是否打开 View Controller 。

在我的应用程序中,我想打开一个警报控件弹出窗口,始终显示推送通知的主体(带有一个确定按钮),并且仅当设置了特定值时,才打开一个警报控件,向用户询问是否他想要打开到达的新内容(通常此内容是基于 web 的内容,打开嵌入在 View Controller 中的 webview)

didReceiveRemoteNotification中:

if let mensaje = userInfo["m"] as? String {
// Here is where I know if the value is set in the notification payload
let alertCtrl = UIAlertController(title: titulo, message: mensaje as String, preferredStyle: UIAlertControllerStyle.Alert)
if url == nil {
alertCtrl.addAction(UIAlertAction(title: "OK", style: .Destructive, handler: nil))
} else {
alertCtrl.addAction(UIAlertAction(title: "Ver receta", style: .Default, handler: {
action in

let storyboard = UIStoryboard(name: "Main", bundle: nil)
//self.window?.rootViewController = storyboard.instantiateViewControllerWithIdentifier("TabbedController") as! UITabBarController
let navigationController = storyboard.instantiateViewControllerWithIdentifier("pushNotificationNavigation") as! UINavigationController
let dVC:NotTestViewController = navigationController.topViewController as! NotTestViewController
// This is for passing the URL to the view Controller
dVC.url = self.url!
self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: {})

})
)
alertCtrl.addAction(UIAlertAction(title: "Cancelar", style: .Destructive, handler: nil))
}
// Find the presented VC...
var presentedVC = self.window?.rootViewController
while (presentedVC!.presentedViewController != nil) {
presentedVC = presentedVC!.presentedViewController
}
presentedVC!.presentViewController(alertCtrl, animated: true, completion: nil)

handler(UIBackgroundFetchResult.NoData)
}

关于ios - 在推送通知 Swift 2 AppDelegate 上加载特定的 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34675098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com