H5页面传值 (https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx0710520917970021a9aa2f341533876505&package=2553003306) 到OC页面
OC用UIWebView加载这个链接
OC代码:
.h
#import "ZWBaseVC.h"
#import <WebKit/WebKit.h>
#import <JavaScriptCore/JavaScriptCore.h>
@interface ZWPayVC : ZWBaseVC<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIWebViewDelegate>
/** 加载html的容器webView */
@property (nonatomic, strong) UIWebView *webview;
/** js与oc 交互桥梁 */
@property (nonatomic, strong) JSContext *jsContext;
/** 链接参数字符串 */
@property (nonatomic, strong) NSString *urlmsg;
@end
.m
#import "ZWPayVC.h"
@interface ZWPayVC ()
@end
@implementation ZWPayVC
- (void)viewDidLoad {
[super viewDidLoad];
[self loadWebView:self.urlmsg];
}
//加载网页
- (void)loadWebView:(NSString *)url_aa {
CGRect rect = [UIScreen mainScreen].applicationFrame;
_webview = [[UIWebView alloc] initWithFrame:rect];
NSURL *url = [NSURL URLWithString:url_aa];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[_webview loadRequest:request];
[self.view addSubview:_webview];
_webview.delegate=self;
}
- (BOOL) webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType) navigationType {
NSDictionary *headers = [request allHTTPHeaderFields];
BOOL hasReferer = [headers objectForKey:@"Referer"]!=nil;
if (hasReferer) {
// .. is this my referer?
return YES;
} else {
// relaunch with a modified request
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSURL *url = [request URL];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"GET"];
[request setValue:@"ja.longliqi.com://" forHTTPHeaderField: @"Referer"];
[self.webview loadRequest:request];
});
});
return NO;
}
}
//内存警告
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }
@end
设置Schemes
![](https://img.haomeiwen.com/i2391824/fd6a015f2c9fbe8e.png)
Info.plist添加LSApplicationQueriesSchemes
![](https://img.haomeiwen.com/i2391824/c5e1c90c2f469d33.png)
网友评论