下载SDK下载HTML 5+ 离线打包SDK (http://ask./article/103)点击下载SDK
下载完成后打开可以看到SDK、demo、Feature-iOS.xls 、IOS平台5+SDK技术白皮书.docx
Feature-iOS.xls:iOS平台各扩展Feature API对应的库文件列表,我们需要参照这个列表逐个添加。 IOS平台5+SDK技术白皮书.docx: 有集成的详细说明(照做即可)
添加 Frameworks 和Libraries参照Feature-ios.xls列表,36行以内所有Frameword 和 Library都是H5+必须的依赖项,需要逐个添加到项目中(Link Binary With Libraries、Other LibrarianFlags中配置) Feature名称:功能包的名称 LinkerFlagsà OtherLinker Flags Library(.a) à Link Binary With Libraries Info àInfo.plist File Frameworkà LinkBinary With Libraries 下面以基础包为例,对项目所需资源进行配置。
添加LinkerFlags Target à BuildSetting à Linking à Other Linker Flags 双击在打开小窗中依次添加-llibNavigator -lcoreSupport -llibPDRCore –llibUI
添加Library 和Framework Target à BuildPhases à Link Binary With Libraries 单击“+”添加.a文件和Framework包
添加资源 Target à BuildPhases à Copy Bundle Resources 单击“+”添加.bundle文件
配置Info.plist File Target à BuildSettings à Packaging à Info.plist File 编辑Info.plist文件, 添加: App Transport SecuritySettings:[类型:Dictionary] Allow Arbitrary Loads:[类型:Boolean][值:YES]
配置引用包的路径 Target à BuildSettings à Search Pathes Framework Search Paths:添加Framework的所在目录的路径 Library Search Paths:添加Library文件的所在目录的路径 引入H5+头文件
配置H5+ SDK资源文件PandoraApi.bundle文件:5+SDK所必需要的资源文件。 位于:SDK/ Bundles/ PandoraApi.bundle,将该文件拖入项目中
或者通过targetàBuild PhasesàCopy Bundle Resources 添加资源文件 添加后结果:
之后我们自己的插件也需要在些配置才能正常工作。 control.xml文件:文件中配置了默认启动应用的APPID,如使用离线打包方式则需要添加此文件,如使用Widget或者Webview方式集成则不需要添加此文件
<key>NSAppTransportSecurity</key><dict> <key>NSAllowsArbitraryLoads</key> <true/></dict>
添加H5+ WebAppTarget à BuildPhases à Copy Bundle Resources 单击“+”,选择下载好的SDK目录下的Pandora文件夹。引用方式选择“folder referneces”.引用成功后,修改目录Pandora/apps/[appid]/www,apps的子目录名称应对control.xml中appid对应,同时修改manifest.json文件中id的值改为control.xml中appid的值相同。
集成功能代码现在开始在原生生成代码的基础上进行集成。
1 设置5+SDK运行模式 在工程的AppDelegate类的添加代码,当应用启动时设置5+SDK的运行模式 -(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 设置当前SDK运行模式 return [PDRCoreinitEngineWihtOptions:launchOptions withRunMode:PDRCoreRunModeAppClient]; } 2 在应用退出时添加销毁5+SDK运行环境 - (void)applicationWillTerminate:(UIApplication *)application { // Called when theapplication is about to terminate. Save data if appropriate. See alsoapplicationDidEnterBackground:. [PDRCore destoryEngine]; }
3 启动5+运行环境 -(void)Start5pEngineAsWidget { PDRCore *h5Engine = [PDRCoreInstance];
CGRect newRect = self.view.bounds; _containerView = [[UIViewalloc] initWithFrame:newRect]; _containerView.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// 设置5+内核的Delegate,5+API在修改状态风格和应用是否全屏时会调用 h5Engine.coreDeleagete = self; h5Engine.persentViewController =self;
[self.viewaddSubview:_containerView]; // 设置WebApp所在的目录,该目录下必须有mainfest.json NSString* pWWWPath = [[[NSBundlemainBundle] bundlePath]stringByAppendingPathComponent:@"Pandora/apps/h5/www/"];
// 设置5+SDK运行的View [[PDRCore Instance] setContainerView:_containerView]; // 传入参数可以在页面中通过plus.runtime.arguments参数获取 NSString* pArgus = @"id=plus.runtime.arguments"; // 启动该应用 pAppHandle = [[[PDRCoreInstance] appManager]openAppAtLocation:pWWWPath withIndexPath:@"index.html" withArgs:pArgus withDelegate:nil]; }
对应头文件引用: #import "PDRCore.h" #import "PDRToolSystem.h" #import "PDRToolSystemEx.h" #import "PDRToolSystem.h" #import "PDRToolSystemEx.h" #import "PDRCoreAppFrame.h" #import "PDRCoreAppManager.h" #import "PDRCoreAppWindow.h" #import "PDRCoreAppInfo.h" 至些H5 Plus集成完成,编译运行。
出错列表汇总: 错误1: -canOpenURL: failed for URL:"hbuilder://" - error: "This app is not allowed to query forscheme hbuilder"
解决方法:在Info.plist中增加“LSApplicationQueriesSchemes类型 array”,再添加该项子项“streamapp”和“hbuilder” 错误2:在线更新h5报错 -canOpenURL: failed for URL:"itms-apps://itunes.apple.com/cn/app/hello-h5+/id682211190?l=zh&mt=8"- error: "This app is not allowed to query for scheme itms-apps"
错误3:原因是引用的“Pandora/apps/h5/www”方式不对,正确引用资源方式是选择“Createfolder referneces”
|
|