Ios@IONICionic3从入门到精通(内含BUG修复)Ionic Framework

ionic3图片选择+照相 目前最好用的插件+BUG修复

2018-03-23  本文已影响572人  凌风x

官方给的 imagePicker插件不仅功能少 而且 问题多,所以师兄就在github找到了一个依然在维护的插件

图片选择器,但是师兄安装使用之后发现BUG也很多。。。

于是我花了一下午时间,看源码、修BUG(表示很痛苦。。。)

但是功夫不负有心人,师兄成功了!!!

下面给小伙伴们介绍一下这个imagePickerPlus的问题及解决办法

1.点击图片返回后图片没有了。。。

在触发 ImagePicker.getPictures方法后,成功的加载出来图片了(和微信很像有木有~),但是很快问题来了,随意点击一张图片后,再返回,图片就没有了,这尼玛。。。如图

图库 点击一张图 返回之后没有图片了

后来经过师兄的不懈努力(AS)终于找到原因了。。。

ImageDataSource.java 中的loaderManager用完没有销毁啊,重复加载了有木有啊!!!这。。。

解决办法:

ImageDataSource.java  做如下修改:

(一)声明一个全局私有的LoaderManager 

private LoaderManager loaderManager=null;

(二)ImageDataSource方法中修改:

loaderManager = activity.getSupportLoaderManager();

(三)onLoadFinished方法最后添加

if(loaderManager.getLoader(LOADER_ALL)!=null){

loaderManager.destroyLoader(LOADER_ALL);

}


2.返回键不好使,一按就GG

这就是疏忽!

解决办法:

在ImageGridActivity.java中添加,并且要引入 import android.view.KeyEvent;

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==0) {

// 按下BACK,同时没有重复

    //Log.d(WZLOG, "onKeyDown()");

  }

return super.onKeyDown(keyCode, event);

}

@Override

public void onBackPressed() {

//Log.d(WZLOG, "onBackPressed()");

  super.onBackPressed();

}

3.各种类似于"Failed resolution of: Landroid/support/v4/view/KeyEventCompat"的BUG

这个就是V4、V7的问题

解决办法:

修改build.gradle配置文件

configurations.all {

resolutionStrategy.eachDependency { DependencyResolveDetails details ->

def requested = details.requested

if (requested.group =='com.android.support') {

if (!requested.name.startsWith("multidex")) {

details.useVersion'25.3.0'

    }

}

}

}

dependencies {

compile fileTree(dir:'libs',include:'*.jar')

// SUB-PROJECT DEPENDENCIES START

    debugCompile(project(path:"CordovaLib",configuration:"debug"))

releaseCompile(project(path:"CordovaLib",configuration:"release"))

compile"com.android.support:support-v4:27.0.0+"

    compile"com.android.support:appcompat-v7:27.0.1"

    compile"com.github.chrisbanes.photoview:library:1.2.4"

    compile"com.android.support:recyclerview-v7:25.1.1"

    compile"com.squareup.picasso:picasso:2.5.2"

    compile"com.nostra13.universalimageloader:universal-image-loader:1.9.5"

    compile"org.xutils:xutils:3.3.36"

    compile"com.github.bumptech.glide:glide:3.7.0"

    // SUB-PROJECT DEPENDENCIES END

}

4.文件路径权限问题,插件不能获取图片

插件内部把选择的图片进行压缩后,放置到了cache中,部分手机不能获取

解决办法:

修改CompressHelper.java

private CompressHelper(Context context) {

this.context = context;

// destinationDirectoryPath = context.getCacheDir().getPath() + File.pathSeparator + FileUtil.FILES_PATH;

//destinationDirectoryPath = context.getCacheDir().getPath()  + FileUtil.FILES_PATH;

    destinationDirectoryPath = context.getExternalCacheDir().getPath()  + FileUtil.FILES_PATH;

}

完美解决

上一篇下一篇

猜你喜欢

热点阅读