【问题标题】:Can't load a push url from my Web View Controller无法从我的 Web 视图控制器加载推送 url
【发布时间】:2015-07-07 09:02:44
【问题描述】:

当我收到我的推送通知时,我从我的应用委托处理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];
    }
} 

这是我的第一个ViewController.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 中加载收到的推送 url,如下所示:

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

编译时一切正常,除了 url 不加载。我做错了什么?

【问题讨论】:

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


    【解决方案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];
    

    【讨论】:

    • 我已经这样做了,链接没问题。我认为这是因为我正在创建 viewController 的一个新实例,但我不知道还能怎么做......
    猜你喜欢
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2016-08-10
    • 1970-01-01
    相关资源
    最近更新 更多