This a issue that have took me down since I am not able to solve it although it seems so easy.
The fact is that I have an iOS app, mainly a webview that loads a website, and I need to load different wen page when notification is received. I am implementing push notification and I have managed to get them working. They are received by the app in the App Delegate and then is when the problem starts. I would like to launch the webview with a specific URL but I don’t know how to do it. I have tried to get the webview instance and passes the URL to it:
“SomeAppDelegate.h”
#import <UIKit/UIKit.h>
@class BrowserViewController;
@interface SomeAppDelegate : UIResponder <UIApplicationDelegate>
@property(nonatomic, retain) IBOutlet BrowserViewController *viewController;
@property (strong, nonatomic) UIWindow *window;
@end
“SomeAppDelegate.m”
#import "SomeAppDelegate.h"
#import "BrowserViewController.h"
@implementation SomeAppDelegate
@synthesize window = _window;
@synthesize viewController;
.........
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[viewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20]];
[self.window addSubview:viewController.webView];
[self.window makeKeyAndVisible];
Another test was to create an instance method within BrowserViewContrller trying to reload from there. I also tried to load story board programatically but when “Is Initial View Controller” is unchecked in storyboard the app crashes just before launch.
I did a lot of googling but I don’t understand pretty much how this life cycle works. I will thank any help.
Probably, you should set your viewcontroller as AppDelegate’s
window.rootViewControllerin the didFinishLaunching:withOptions: method of your app delegate instead of adding it’s webView as window subview – because webView is only loaded after UIViewController’s methodviewDidLoadgot called – that means that your webView might not be loaded when you’re trying to reload it with request.