简体   繁体   中英

Can't load a push url from my Web View Controller

When I receive my push notification, from my app delegate I handle the push in handleRemoteNotifications:(NSDictionary *)userInfo and from there I call a firstViewController class method to send the push url, like this:

-(void)handleRemoteNotifications:(NSDictionary *)userInfo {
    // get link
    NSDictionary *aps = (NSDictionary *)[userInfo objectForKey:@"aps"];
    if ([aps objectForKey:@"link"])
    {
        NSString* jobID = [NSString stringWithFormat:@"%@",[aps objectForKey:@"link"]];

        NSLog(jobID,nil);

        [FirstViewController viewController:jobID];
    }
} 

this is my firstViewController.h:

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController <UIWebViewDelegate>



@property (readwrite, strong, nonatomic) IBOutlet UIWebView *firstview;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *back;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *stop;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *refresh;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *forward;


+(void)viewController:(NSString*)link;
- (void)updateButtons;
@end 

An I'm trying to load the received push url in the current webView like this:

+(void)viewController:(NSString*)link{
    NSURL *url = [NSURL URLWithString:link];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    FirstViewController *new = [[FirstViewController alloc]init];
    [new loadPush:(NSURLRequest*)requestObj];

}
-(void)loadPush:(NSURLRequest*)requestObj{

    [_firstview loadRequest:requestObj];
}

Everything works fine when I compile, except the url don't load. What am I doing wrong?

Can you put a NSLog after NSURL *url to test the link string and check the NSURL is not nil? Then if you receive a good URL, try to test it on your browser.

EDIT:

Maybe you have to add a webView on the new ViewController instanced.

UIWebView *webView = [[UIWebView alloc]     initWithFrame:self.view.bounds];

self.webView = webView;

[self.view addSubview:self.webView];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM