//在工程的AppDelegate类的添加代码,当应用启动时设置5+SDK的运行模式
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// 设置当前SDK运行模式
return [PDRCore initEngineWihtOptions:launchOptions withRunMode: PDRCoreRunModeWebviewClient];
}
//在应用退出时添加销毁5+SDK运行环境
- (void)applicationWillTerminate:(UIApplication *)application{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[PDRCore destoryEngine];
}
当前控制器中
// 启动5+运行环境
1)、widget集成方式
-(void)Start5pEngineAsWidget{
PDRCore *h5Engine = [PDRCore Instance];
CGRect newRect =CGRectMake(0, -StatusBarHeight, SCREENWIDTH, SCREENHEIGHT+StatusBarHeight);
_containerView = [[UIView alloc] initWithFrame:newRect]; _containerView.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// 设置5+内核的Delegate,5+API在修改状态风格和应用是否全屏时会调用 h5Engine.coreDeleagete = self;
h5Engine.persentViewController =self;
[self.view addSubview:_containerView];
// 设置WebApp所在的目录,该目录下必须有mainfest.json
NSString* pWWWPath = [[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:@"Pandora/apps/H57DE8278/www/"];
// 设置5+SDK运行的View
[h5Engine setContainerView:_containerView];
// 传入参数可以在页面中通过plus.runtime.arguments参数获取
NSString* pArgus = @"id=plus.runtime.arguments";
// 启动该应用
pAppHandle = [[[PDRCore Instance] appManager]openAppAtLocation:pWWWPath withIndexPath:@"index.html" withArgs:pArgus withDelegate:nil];
}
2)、webview集成方式
// 启动5+运行环境
-(void)Start5pEngineAsWidget
{
PDRCore* pCoreHandle = [PDRCore Instance];
if (pCoreHandle != nil)
{
NSString * pFilePath = [NSString stringWithFormat:@"file://%@/%@", [NSBundle mainBundle].bundlePath, @"Pandora/apps/H57DE8278/www/index.html#/home/first"];
[pCoreHandle start];
// 如果路径中包含中文,或Xcode工程的targets名为中文则需要对路径进行编码
// NSString * pFilePath1 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pFilePath, NULL, NULL, kCFStringEncodingUTF8 ));
// 用户在集成5+SDK时,需要在5+内核初始化时设置当前的集成方式,
if (@available(iOS 11.0, *)) {
CGRect StRect = CGRectMake(0, StatusBarHeight, SCREENWIDTH, SCREENHEIGHT-StatusBarHeight-BottomHeight);
appFrame = [[PDRCoreAppFrame alloc] initWithName:@"WebViewID1" loadURL:pFilePath frame:StRect];
} else {
CGRect StRect = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT-BottomHeight);
appFrame = [[PDRCoreAppFrame alloc] initWithName:@"WebViewID1" loadURL:pFilePath frame:StRect];
}
if (appFrame) {
[pCoreHandle.appManager.activeApp.appWindow registerFrame:appFrame];
[self.view addSubview:appFrame];
}
}
}