[英]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: 当我收到推送通知时,从我的应用程序委托中处理
handleRemoteNotifications:(NSDictionary *)userInfo
的推送,然后从那里调用firstViewController
类方法来发送推送URL,如下所示:
-(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: 这是我的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: 我正在尝试将接收到的推送网址加载到当前的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];
}
Everything works fine when I compile, except the url don't load. 我编译时一切正常,除了不加载url。 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? 您可以在NSURL * url之后放置NSLog来测试链接字符串并检查NSURL是否为nil吗? Then if you receive a good URL, try to test it on your browser.
然后,如果您收到一个不错的URL,请尝试在浏览器上对其进行测试。
EDIT: 编辑:
Maybe you have to add a webView on the new ViewController instanced. 也许您必须在实例化的新ViewController上添加一个webView。
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView = webView;
[self.view addSubview:self.webView];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.