Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS Swift:收到推送通知后将新url加载到Web视图_Ios_Objective C_Iphone_Swift_Webview - Fatal编程技术网

IOS Swift:收到推送通知后将新url加载到Web视图

IOS Swift:收到推送通知后将新url加载到Web视图,ios,objective-c,iphone,swift,webview,Ios,Objective C,Iphone,Swift,Webview,我有一个带有网络视图和推送通知的Swift 2.0应用程序。 每次应用程序启动时,Webview都会工作 收到推送通知后,我需要调用另一个url。 (对推送消息作出反应) 如何访问appdelegate函数DidReceiveMemoteNotification中的webview元素?这可能吗 到目前为止,我的代码是: ViewController: class ViewController: UIViewController,UIWebViewDelegate { @IBOutlet var

我有一个带有网络视图和推送通知的Swift 2.0应用程序。 每次应用程序启动时,Webview都会工作

收到推送通知后,我需要调用另一个url。 (对推送消息作出反应)

如何访问appdelegate函数DidReceiveMemoteNotification中的webview元素?这可能吗

到目前为止,我的代码是:

ViewController:
class ViewController: UIViewController,UIWebViewDelegate { 
@IBOutlet var containerView: UIView!
@IBOutlet var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.webView.delegate = self;

        var urlStringHost = "http://www.exampleUrl.com"

        let url = NSURL(string: urlStringHost)

        let request = NSMutableURLRequest(URL: url!)
        request.HTTPMethod = "POST"

        webView.loadRequest(request)
}
代表:

// Push Empfangen
func application(application: UIApplication, didReceiveRemoteNotification userInfo:[NSObject : AnyObject]) {
    print("push empfangen")
    print(userInfo)
    application.applicationIconBadgeNumber = 0


    // Load some new url to the existing webview (not working)
    //webview?.loadRequest(request)




}

非常感谢。

通过使用NSNotificationCenter,您可以做到这一点

首先在viewcontroller中设置通知和设置选择器

func viewDidLoad() 
{
    super.viewDidLoad()

    //add observer for load request in webview when receive remote notification.
    NSNotificationCenter.defaultCenter().addObserver(self, selector:"PushReceiver:", name: "PushReceived", object: nil)
}

//When post notification then below method is called.
func PushReceiver(notifi: NSNotification) 
{
    var dicNotifi: [NSObject : AnyObject] = notifi.userInfo
    NSLog("notificiation Info %@ \n", dicNotifi)
}
当收到远程通知时,然后在AppDelegate类的DidReceiveMemoteNotification方法中发布通知

func application(application: UIApplication, didReceiveRemoteNotification userInfo:[NSObject : AnyObject]) 
{
    print("push empfangen")
    print(userInfo)
    application.applicationIconBadgeNumber = 0

    //post notification.
     NSNotificationCenter.defaultCenter().postNotificationName("PushReceived", object: nil, userInfo: userInfo)
}

你好,这正是我要找的。因此,我可以在控制器中使用您的解决方案而不是在委托中处理推送事件后的请求。这太完美了。很多感谢。如果我的答案对你有帮助,那么请考虑把答案标记为正确,这样别人就能很快找到答案。我做到了,但它只有在我收到15的答复时才有效。(我是新来的)你可以批准。有关更多详细信息,请参阅此链接。通过批准,其他人可以很快找到答案。好的,我现在将其标记为已接受答案。只有在15点之前投票才有效:)再次感谢您提供的信息