Ios 收到通知后,我想更改uiwebview
我收到的通知包含要在Ios 收到通知后,我想更改uiwebview,ios,objective-c,uiwebview,Ios,Objective C,Uiwebview,我收到的通知包含要在UIWebView中打开的url。但是我无法从我的AppDelegate访问UIWebview(这是接收通知的地方) 一种方法是发布UIWebView收到的通知。查看或。在我的应用程序中,我使用了以下内容,此时屏幕上已显示UIWebView: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSString
UIWebView
中打开的url。但是我无法从我的AppDelegate
访问UIWebview
(这是接收通知的地方)
一种方法是发布UIWebView
收到的通知。查看或。在我的应用程序中,我使用了以下内容,此时屏幕上已显示UIWebView
:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *urlString = [userInfo objectForKey:@"url"];
if( [self.window.rootViewController isKindOfClass:[UINavigationController class]] ){
UINavigationController *currentNavigationController = (UINavigationController*)self.window.rootViewController;
if( [currentNavigationController.visibleViewController isKindOfClass:[NHCallVC class]] ){
SomeViewController *currentViewController = (SomeViewController*)currentNavigationController.visibleViewController;
[currentViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
}
}
带有UINavigationController
的结构似乎很复杂,但这是我设置应用程序所需要的。这在你的应用程序中可能会有所不同
其思想是获取打开的viewcontroller,并在UIWebView
上加载URL。代码假设带有UIWebView
的UIViewController
当前处于打开状态。如果要在UIWebView
中打开url之前导航到正确的UIViewController
,则应更改代码将观察者放置到UIWebView所在的视图,例如:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recievedNotification:) name:@"ReceivedNotification" object:nil];
在ReceivedNotification函数中编写适当的代码,该函数将更改UIWebView的目标url
并在APP Delegate中的didReceiveRemoteNotification功能中发布通知,例如:
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedNotification" object:nil];
祝你好运。谢谢,我会试试看:)
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedNotification" object:nil];