无法从我的Web View Controller加载推送网址

时间:2015-04-28 13:16:03

标签: ios objective-c uiwebview storyboard interface-builder

当我收到推送通知时,我会从我的应用代表处理handleRemoteNotifications:(NSDictionary *)userInfo中的推送,并从那里调用firstViewController类方法发送推送网址,如下所示:

-(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];
    }
} 

这是我的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 

我试图在当前的webView中加载收到的推送网址,如下所示:

+(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];
}

编译时一切正常,除了网址没有加载。我做错了什么?

1 个答案:

答案 0 :(得分:-1)

你可以在NSURL * url之后放一个NSLog来测试链接字符串并检查NSURL是不是nil?然后,如果您收到一个好的URL,请尝试在浏览器上测试它。

编辑:

也许你必须在新的ViewController实例上添加一个webView。

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

self.webView = webView;

[self.view addSubview:self.webView];
相关问题