I am trying to load the url which comes with payload under notification in webview. For webview I have a view controller named WebViewController.
In order to catch notification click I have added the following code in AppDelegate.m:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
if (app.applicationState == UIApplicationStateInactive )
{
NSDictionary *userInfo=notif.userInfo;
[[NSNotificationCenter defaultCenter] postNotificationName: @"TestNotification" object:nil userInfo:userInfo];
}
}
The above will fire the event when notification is clicked. In order to hook that eevent I added this piece of code in my WebViewController:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
}
The code for "receiveTestNotification" method which I added in the same web view controller is:
- (void) receiveTestNotification:(NSNotification *) notif {
NSDictionary *userInfo=notif.userInfo;
NSString *url=[userInfo valueForKey:@"SiteURLKey"];
NSString *str = [NSString stringWithFormat: @"%@%@", [Utils getCommuntityURL],url];
NSURL *siteURL = [NSURL URLWithString:str];
[self.webView loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];
// Show webView control
[self.webView setHidden:false];
[self.webView loadRequest:[Utils getNSURLRequest:siteURL]];
[self.webView reload];
}
I can confirm I am able to hit this method when the notification is clicked. I can get the correct "siteURL" even but the webiview doesn't reloads/refreshes. It just stays blank. Is there anything wrong I am doing above
0 comments:
Post a Comment