3***@qq.com
3***@qq.com
  • 发布:2017-01-12 15:28
  • 更新:2019-09-05 17:38
  • 阅读:2351

在iOS原生today widget 页面当中跳转到指定的html页面当中

分类:5+ SDK
iOS
  在iOS的today widget 中点击 跳转到主程序应用当中 并会调用到AppDelegate 中的  
  • (BOOL)application:(UIApplication )application handleOpenURL:(NSURL )url;
    方法,在这里我可以通过url.host 和url.scheme 拿到我想要跳转的页面 例如url.host = main.html 也就是说我想跳转到应用下main.html这个页面。

    之前提交过一个类似的问题:

http://ask.dcloud.net.cn/question/25590?notification_id-131675rf-falseitem_id-37742__answer_id-37742__single-TRUE#!answer_37742

按照 @DCloud_SDK_骁骑 给我的意见 参考了 文章 http://ask.dcloud.net.cn/article/453
Native代码调用当前运行应用的指定HTML页面内的JS方法 这个标题内的内容

PDRCoreAppFrame* pFrame = [[[[[PDRCore Instance] appManager] activeApp] appWindow] getFrameByName:@"main.html"];  
    if (pFrame)  
    {  
        // 找到指定的页面并调用evaluatingJavaScriptAndFetchCommand方法调用该html页面的JS方法  
        [pFrame evaluatingJavaScriptAndFetchCommand:@"InputJSFunctionNameInHtmlPage()"];  
    }

导入相应的头文件后,发现pFrame还是为空 猜测应该是需要registerFrame 所以,我在openURL方法当中重新注册了frame


PDRCore*  pCoreHandle = [PDRCore Instance];  
NSString* pFilePath = [NSString stringWithFormat:@"file://%@/%@", [NSBundle mainBundle].bundlePath,  
                               [NSString stringWithFormat:@"Pandora/apps/%@/www/main.html",APPID]];  

        CGRect StRect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20);  

        //创建runtime页面  
        PDRCoreAppFrame *appFrame = [[PDRCoreAppFrame alloc] initWithName:@"mainID"  //frameID 页面标示  
                                                                  loadURL:pFilePath      //pagePath 页面地址 支持http:// file:// 本地地址  
                                                                    frame:StRect];       //frame 页面位置  

        NSString* pStringDocumentpath = [NSString stringWithFormat:@"%@/Pandora/apps/%@/www/",  
                                         [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0],APPID];  
        [pCoreHandle.appManager.activeApp.appInfo setWwwPath:pStringDocumentpath];  

        PDRCoreAppWindow *appwindow = [[[[PDRCore Instance] appManager] activeApp] appWindow];  
       [pCoreHandle.appManager.activeApp.appWindow registerFrame:appFrame];

此时,通过代码

  PDRCoreAppFrame* pFrame = [[[[[PDRCore Instance] appManager] activeApp] appWindow] getFrameByName:@"mainID"];  
if (pFrame) {  
//        [pFrame evaluateJavaScript:@"testFunc()" completionHandler:nil];  
        [pFrame dispatchDocumentEvent:@"openDoor"];  
    }

能拿到该pFrame 想通过evaluateJavaScript 该方法调用main.html页面的testFunc( )方法。第一次点击today widget后,能跳转到主页面,但是不会调用该方法,第二次在点击today widget 跳转到主页面 界面卡死不动!原因不知。所以改用dispatchDocumentEvent 通过分发事件的方式,在main.html页面当中 写入相应代码

document.addEventListener('openDoor',function(e){  
                                                alert('测试调用方法!!');  
                                                })

发现第一次跳转到主程序不用调用,第二次才会调用。此时通过Safari浏览器查看 发现有多


个main.html
打印appwindow.allFrames 发现每次有多个frame


"<PDRCoreAppFrame: 0x100c2d720; frame = (0 0; 375 647); clipsToBounds = YES; layer = <CALayer: 0x17403e540>>",  
    "<PDRCoreAppFrame: 0x100c472b0; frame = (0 0; 375 647); clipsToBounds = YES; layer = <CALayer: 0x17402f840>>"  

我现在的问题是。在手机开机,未打开任何应用程序下,找到对应应用的today widget 点击第一次,跳转到主界面,能跳转成功,无任何其他反应。点击home键,第二次点击today widget ,跳转到主界面,任然没有任何反应。点击home键,第三次点击today widget ,,跳转到主界面,此时,弹出弹出框!达到想要的结果。

请问能帮帮我么,有点急。。。。

2017-01-12 15:28 负责人:无 分享
已邀请:
逞英雄

逞英雄

你好需要导入哪些头文件啊

该问题目前已经被锁定, 无法添加新回复