iOS平台5+SDK集成

 
 

iOS嵌套H5项目,5+SDK集成

  • 网上H5页面与原生框架的交互很多,但是在原生框架中嵌入H5页面资料不多。(在多次HBuilder官方人员的指导下才完成,主要官网的文档说明太少)
  • 5+SDK下载地址
  • 下载好的文件包
    SDK.png
  • SDk文件包所以文件
    SDK包文件.png
有三种方式集成
- WebView方式集成
    用户可在任何页面酱HTML5+SDK的页面以webView的形式独立显示
- Widget 方式集成
    运行方式和独立运行方式类似,开发者子在集成时可在需要的为止启动HTML5+SDK,显示指定的HTML5+应用
- 独立应用方式集成
    使用独立应用方式。(当需要集成的H5页面能单独运行,就采用此方法集
  • 在工程中引入SDK扩展功能的.a文件,开发这可以根据需求添加不同的扩展插件。必须引入的是liblibPDRCore.a,liblibUI.a,liblibNativeUI.a,liblibWidget.a,liblibNavigator.a,libcoreSupport.a(这些静态库在Libs中)
  • 还需要在Bundles文件夹中把PandoraApi.bundle加入到工程中(官方文档就没用提到这个,比较坑)
  • ImageIO.framework
  • webkit.framework
  • MobileCoreServices.framework

  • Link.png
    ,最后加入这些系统库!(最后三个是我另外添加的,要不继续报错)
  • !!!一个都不能少,不然会运行不起来
工程配置
  • 首先在工程的Build Setting -> Linking -> Other Linker Flags 双击该项在打开的下拉列表中添加“-ObjC”
引入5+SDK头文件
  • 打开5+SDK所在目录,拖动inc目录到Xcode工程,文件夹类型选择“Create Groups”

    1.png
  • 添加control.xml文件:配置文件的APPID

    2.png
  • 添加资源到工程(需要添加的H5资源):在工程目录下创建 “Pandora/apps/[appid]/www”目录,并将所有应用资源拷贝到其下的www目录中(appid就是control.xml中的APPID)。拖动“Pandora”目录到Xcode工程内,并选择“Create folder referneces”

    3.png
代码
  • 独立应用方式
//在工程的AppDelegate类的添加代码,当应用启动时设置5+SDK的运行模式

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 设置当前SDK运行模式
   return [PDRCore initEngineWihtOptions:launchOptions withRunMode:PDRCoreRunModeAppClient];
}
//在应用退出时添加销毁5+SDK运行环境
- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    [PDRCore destoryEngine];
}

//启动5+运行环境
-(void)Start5pEngineAsWidget
{
    // 设置WebApp所在的目录,该目录下必须有mainfest.json
    NSString* pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/(appId)/www"];

    // 如果路径中包含中文,或Xcode工程的targets名为中文则需要对路径进行编码
    //NSString* pWWWPath2 =  (NSString *)CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pTempString, NULL, NULL,  kCFStringEncodingUTF8 );

    // 设置5+SDK运行的View
    [[PDRCore Instance] setContainerView:_containerView];
    // 传入参数可以在页面中通过plus.runtime.arguments参数获取
    NSString* pArgus = @"id=plus.runtime.arguments";
    // 启动该应用
    pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"index.html" withArgs:pArgus withDelegate:nil];

    // 如果应用可能会重复打开的话建议使用restart方法
//[[[PDRCore Instance] appManager] restart:pAppHandle];
}
  • webView集成方式(Widget方式一样)
//在工程的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+运行环境
-(void)Start5pEngineAsWebView
{
    PDRCore*  pCoreHandle = [PDRCore Instance];
    if (pCoreHandle != nil)
    {

        // 单页面集成时可以设置打开的页面是本地文件或者是网络路径
        NSString* pFilePath = [NSString stringWithFormat:@"file://%@/%@", [NSBundle mainBundle].bundlePath, @"Pandora/apps/(appId)/www/***.html"];

        // 如果路径中包含中文,或Xcode工程的targets名为中文则需要对路径进行编码
        //NSString* pFilePath =  (NSString *)CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pTempString, NULL, NULL,  kCFStringEncodingUTF8 );

        CGRect StRect = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20);

        appFrame = [[PDRCoreAppFrame alloc] initWithName:@"WebViewID1" loadURL:pFilePath frame:StRect];
        // 单页面运行时设置Document目录
        NSString* pStringDocumentpath = [NSString stringWithFormat:@"%@/Pandora/apps/HelloH5/www/", [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
        [pCoreHandle.appManager.activeApp.appInfo setWwwPath:pStringDocumentpath];
        [pCoreHandle.appManager.activeApp.appWindow registerFrame:appFrame];

        [_containerView addSubview:appFrame];
    }
}
扩展插件配置
  • 如需要在5+页面中使用分享功能首先必须要在工程中引入“liblibShare.a”文件
  • 微信分享:

    • 需要添加的静态库:静态库文件在SDK/libs目录下
      • liblibShare.a
      • libweixinShare
    • libWeChatSDK
    • 在info.plist里面添加微信平台申请来的appSecret和appid

4.png

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值