Phonegap App需要一些时间来加载index.html页面

时间:2013-08-01 11:38:40

标签: ios cordova

我正在为iOS制作Phonegap应用。当应用程序启动时,有时需要时间来加载index.html页面。在控制台中,它在webViewDidFinishLoading调用中加载页面时显示日志:

Finished load of: file:///var/mobile/Applications/4749F774-52F7-467C-9B0B-8C6AF95C518B/app-name/www/index.html 

但有时这个方法不会调用,因此它不会显示日志。在该方法上还有一些其他原生初始化。

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
    NSLog(@"Finished load of: %@", theWebView.request.URL);
    // It's safe to release the lock even if this is just a sub-frame that's finished loading.
    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];

    // The .onNativeReady().fire() will work when cordova.js is already loaded.
    // The _nativeReady = true; is used when this is run before cordova.js is loaded.
    NSString* nativeReady = @"try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}";
    // Don't use [commandDelegate evalJs] here since it relies on cordova.js being loaded already.
    [self.webView stringByEvaluatingJavaScriptFromString:nativeReady];

    /*
     * Hide the Top Activity THROBBER in the Battery Bar
     */
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

    [self processOpenUrl];

    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPageDidLoadNotification object:nil]];
}

然而,它在屏幕上显示了index.html页面,但它没有执行任何本机实现,如本机警报,Twitter共享等。

如何解决此问题?

更新:index.html页面

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, target-densitydpi=device-dpi" />

        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700&subset=latin,latin-ext" rel='stylesheet' type='text/css'>

        <!--<link rel="stylesheet" type="text/css" href="jquerymobile/jquery.mobile-1.1.0.min.css" />-->
        <link rel="stylesheet" type="text/css" href="jquerymobile/jquery.mobile-1.2.1.min.css" />

        <link rel="stylesheet" type="text/css" href="css/addingcf.css" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="css/sign_keyboard.css" />
        <link rel="stylesheet" type="text/css" href="css/registration.css" />
        <link rel="stylesheet" type="text/css" href="css/registrsuccessful.css" />
        <link rel="stylesheet" type="text/css" href="css/afteractivation.css" />
        <link rel="stylesheet" type="text/css" href="css/my_profile.css" />
        <link rel="stylesheet" type="text/css" href="css/changepassword.css" />
        <link rel="stylesheet" type="text/css" href="css/screen4.css" />
        <link rel="stylesheet" type="text/css" href="css/updatefailed.css" />
        <link rel="stylesheet" type="text/css" href="css/viewmy_ce.css" />
        <link rel="stylesheet" type="text/css" href="css/view.css" />
        <link rel="stylesheet" type="text/css" href="css/ViewSingle_ce.css" />
        <link rel="stylesheet" type="text/css" href="css/emailce.css" />
        <link rel="stylesheet" type="text/css" href="css/upgrd.css" />
        <link rel="stylesheet" type="text/css" href="css/questions.css" />
        <link rel="stylesheet" type="text/css" href="css/le_Light_and_Pro_MultiTab1.css" />


        <title>Hello World</title>

        <script type="text/javascript" src="cordova-2.5.0.js"></script>
        <script type="text/javascript" src="jquerymobile/jquery-1.7.2.min.js"></script>
        <!--<script type="text/javascript" src="jquerymobile/jquery.mobile-1.1.0.min.js"></script>-->
        <script type="text/javascript" src="jquerymobile/jquery.mobile-1.2.1.min.js"></script>
        <script type="text/javascript" src="jquerymobile/jqm.autoComplete-1.5.1-min.js"></script>
        <script type="text/javascript" src="jquerymobile/overthrow.js"></script>
        <script type="text/javascript" src="plugin_js/testflight.js"></script>
        <script type="text/javascript" src="plugin_js/TSReport.js"></script>



        <script type="text/javascript" src="js/login_page.js"></script>

        <script type="text/javascript" src="js/ChildBrowser.js"></script>
        <script type="text/javascript" src="js/FBConnect.js"></script>
        <script type="text/javascript" src="js/register_page.js"></script>
        <script type="text/javascript" src="js/register_success_page.js"></script>
        <script type="text/javascript" src="js/activated_page.js"></script>
        <script type="text/javascript" src="js/home_page.js"></script>
        <script type="text/javascript" src="js/profile_page.js"></script>
        <script type="text/javascript" src="js/changepassword_page.js"></script>
        <script type="text/javascript" src="js/forgotPassword.js"></script>
        <script type="text/javascript" src="js/addce_page.js"></script>
        <script type="text/javascript" src="js/reset_page.js"></script>
        <script type="text/javascript" src="js/getting_started_page.js"></script>
        <script type="text/javascript" src="js/cookies.js"></script>
        <script type="text/javascript" src="js/common.js"></script>
        <script type="text/javascript" src="js/modifyce_page.js"></script>
        <script type="text/javascript" src="js/noce_page.js"></script>
        <script type="text/javascript" src="js/viewce_page.js"></script>
        <script type="text/javascript" src="js/requestLink_page.js"></script>
        <script type="text/javascript" src="js/viewSingleCe_page.js"></script>
        <script type="text/javascript" src="js/emailce_page.js"></script>
        <script type="text/javascript" src="js/upgrade_page.js"></script>
        <script type="text/javascript" src="js/question_page.js"></script>
        <script type="text/javascript" src="js/about_page.js"></script>
        <script type="text/javascript" src="js/gs_addce_page.js"></script>
        <script type="text/javascript" src="js/gs_viewce_page.js"></script>
        <script type="text/javascript" src="js/gs_freesub_page.js"></script>
        <script type="text/javascript" src="js/delete_page.js"></script>
        <script type="text/javascript" src="js/manage_subs_page.js"></script>
        <script type="text/javascript" src="js/cancel_subs_page.js"></script>
        <script type="text/javascript" src="js/terms_page.js"></script>
        <script type="text/javascript" src="js/test.js"></script>
        <script type="text/javascript" src="js/database.js"></script>


        <script type="text/javascript" src="plugin_js/TwitterPlugin.js"></script>
        <script type="text/javascript" src="plugin_js/ShareKitPlugin.js"></script>
        <script type="text/javascript" src="plugin_js/PrintPlugin.js"></script>
        <script type="text/javascript" src="plugin_js/MECLPayPalPlugin.js"></script>
        <script type="text/javascript" src="plugin_js/PushNotification.js"></script>

        <style type="text/css">
            body { font-family: 'Open Sans', sans-serif; 

            -webkit-touch-callout: none;
            -webkit-user-select: none;

            }
        </style>


    </head>
    <body>

</body>
</html>

0 个答案:

没有答案