-
Notifications
You must be signed in to change notification settings - Fork 99
iOS APIs
zhangyanqiang edited this page Apr 26, 2018
·
1 revision
Page Data 是初始化小程序运行环境时注入的静态变量,包含小程序运行时默认信息,也可以在小程序路由跳转时携带必要信息
参数 | 参数描述 | 参数类型 | 备注 |
---|---|---|---|
displayWidth | 小程序窗口宽度 | int | |
displayHeight | 小程序窗口高度 | int | |
packageid | 小程序包ID | String | |
pageid | 小程序页面ID | String |
var goPage={
"path": page_path,
"data": page__data__what__ever,
}
__base__.triggerEvent("goPage", goPage);
NSString* json = @"{}";
json = [@"__page__data =" stringByAppendingString:json];
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
[container evaluateScript:data];
NSString* json = @"{}";
if (nil != self.arguments) {
NSError* error = nil;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self.arguments
options:NSJSONWritingPrettyPrinted
error:&error];
json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
json = [@"__page__data =" stringByAppendingString:json];
[self.container evaluateScript:[json dataUsingEncoding:NSUTF8StringEncoding]];
js端通过Triggerevent可以调用native的方法实现更多拓展,在demo中实现gopage跳转页面的接口,后续可以拓展更多的功能。
JSExportAs(triggerEvent, -(void) triggerEvent:(NSString*)type arguments:(JSValue *)arguments);
-(void)triggerEvent:(NSString *)type withArguments:(id)arguments{
NSDictionary* args = __safe_convert(arguments, NSDictionary);
if ([type isEqualToString:@"goPage"]) {
NSString* pagename = __safe_convert([args objectForKey:@"path"], NSString);
NSDictionary* data = __safe_convert([args objectForKey:@"data"], NSDictionary);
if (pagename != nil && self.handler) {
__weak QIYIContainer* ws = self;
dispatch_async(dispatch_get_main_queue(), ^{
[ws.handler startNewPage:pagename withArguments:data];
});
}
}
}