有关cdvfile:// protocol

时间:2016-12-28 18:25:59

标签: javascript ios cordova

目前正在开发Cordova App。

我使用<img class="profile-thumbnail" src="cdvfile://localhost/persistent/Photo/mypicture.jpg">在视图中显示一些内容。

当我使用文件API生成新的mypicture.jpg来覆盖现有的$('.profile-thumbnail').attr('src','cdvfile://localhost/persistent/Photo/mypicture.jpg'); 时,图片会从视图中消失,并且在我杀死并重新启动应用之前永远不会回来。

我尝试:

// Create new image size for our hero image
add_image_size( 'hero-image', 1400, 400, TRUE ); // creates a hero image size

// Hook after header area
add_action( 'genesis_after_header', 'bw_hero_image' );

function bw_hero_image() {
// If it is a page and has a featured thumbnail, but is not the front page do the following...
    if (has_post_thumbnail() && is_page() ) {
        // Get hero image and save in variable called $background
        $image_desktop = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'hero-image' );
        $image_tablet = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'large' );
        $image_mobile = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'medium' );

        $bgdesktop = $image_desktop[0];
        $bgtablet = $image_tablet[0];
        $bgmobile = $image_mobile[0];

// You can change above-post-hero to any class you want and adjust CSS styles
        $featured_class = 'above-post-hero';

 ?> 
<div class='<?php echo $featured_class; ?>'><h1 class="custom-title">AJ Customs Finishes in Las Vegas<br>Call 702-795-7338 today!</h1></div>
<style>
    <?php echo ".$featured_class "; ?> {background-image:url( <?php echo $bgmobile; ?>);height:176px;}

        @media only screen and (min-width : 480px) {       
        <?php echo ".$featured_class "; ?> {background-image:url(<?php echo $bgtablet;?>);height:276px;}
        }
        @media only screen and (min-width : 992px) {       
        <?php echo ".$featured_class "; ?> {background-image:url(<?php echo $bgdesktop;?>);height:400px;}
        }
</style>
<?php
    } 
}

我的存储成功通话后,但在更新后仍然无法显示正确的图片。

当我重新启动应用时,新文件会正确显示。

那么,cdvfile://协议如何处理更新?

更新文件后是否有要刷新的缓存?

处理此类请求的任何首选技术?

1 个答案:

答案 0 :(得分:0)

我发现了问题,我存储更新图片的方式不正确。 我创建了文件,但是我在其中写入图片的方式是错误的。所以它显示了一个空文件。