terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 301 forks source link

Permission problem on iOS/Ionic 2 #86

Closed Servuc closed 7 years ago

Servuc commented 7 years ago

Hi guys,

I know that a iOS dev is requested, but I also have a little problem about permission on iOS.

When user arrived for the time on library page, no request is make, only an error message prompted. Strangely, it's work fine on Android.

Some code :

First, library page :

export class PhotoLibraryPage {

  @ViewChild("photosList", { read: ViewContainerRef }) container : ViewContainerRef;

  constructor(public navCtrl: NavController, private componentFactoryResolver: ComponentFactoryResolver, private photoLibrary: PhotoLibrary) {
    const myPhotoLibraryComponent = this.componentFactoryResolver.resolveComponentFactory( PhotoLibraryEntry );

    let that = this;
    Loading.display( LoadingState.LOADING );
    this.photoLibrary.requestAuthorization({read: true}).then(() => {
      that.photoLibrary.getLibrary().subscribe({
        next: library => {
          library.forEach(function(libraryItem) {
            console.log(libraryItem.thumbnailURL);// Cross-platform access to thumbnail
            console.log(libraryItem.fileName);
            let myPhoto = that.container.createComponent( myPhotoLibraryComponent );
            myPhoto.instance.name = libraryItem.fileName;
            myPhoto.instance.path = libraryItem.thumbnailURL;
          });
        },
        error: err => { Loading.display( LoadingState.PROBLEM, "Can't load images from your phone."); Loading.hide( Loading.LONG_DISPLAYING_TIME );},
        complete: () => { Loading.hide(); }
      });
    })
    .catch(err => {
      console.log("Permissions weren't granted")
      Loading.display( LoadingState.PROBLEM, "The app doesn't have authorization to access to your photos.");
      Loading.hide( Loading.LONG_DISPLAYING_TIME );
    });
  }

  ionViewWillLeave() : void {
    Loading.hide();
  }
}

Users get all the time : The app doesn't have authorization to access to your photos. (Tested on iOS SE simulator and iPhone 5)

app.module.ts :

@NgModule({
  declarations: [
    MyApp,
    /* .... */
    PhotoLibraryPage,
    PhotoLibraryEntry,
    CDVPhotoLibraryPipe,
    /* .... */
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    /* .... */
    PhotoLibraryPage,
    PhotoLibraryEntry,
    /* .... */
  ],
  providers: [
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    /* .... */
    Device,
    PhotoLibrary,
    Geolocation,
    Globalization,
    SecureStorage
  ]
})

I don't know lot of things on iPhone dev, but should I add permission line like on Android ?

My package.json :

    "dependencies": {
        "@angular/common": "2.4.8",
        "@angular/compiler": "2.4.8",
        "@angular/compiler-cli": "2.4.8",
        "@angular/core": "2.4.8",
        "@angular/forms": "2.4.8",
        "@angular/http": "2.4.8",
        "@angular/platform-browser": "2.4.8",
        "@angular/platform-browser-dynamic": "2.4.8",
        "@angular/platform-server": "2.4.8",
        "@ionic-native/core": "^3.12.1",
        "@ionic-native/geolocation": "^3.12.1",
        "@ionic-native/globalization": "^3.12.1",
        "@ionic-native/photo-library": "^3.12.1",
        "@ionic-native/secure-storage": "^4.1.0",
        "@ionic/storage": "^2.0.0",
        "cordova-browser": "^4.1.0",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.1",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "2.2.0",
        "ionic-native": "2.8.1",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "moment": "^2.18.1",
        "runtastic-js": "^1.0.1",
        "rxjs": "5.0.1",
        "sw-toolbox": "3.4.0",
        "zone.js": "0.7.2"
    },
    "devDependencies": {
        "@ionic/app-scripts": "1.1.4",
        "@ionic/cli-plugin-cordova": "1.4.1",
        "@ionic/cli-plugin-ionic-angular": "1.3.2",
        "typescript": "2.0.9"
    },
    "cordovaPlugins": [
        "cordova-plugin-device",
        "cordova-plugin-whitelist",
        "cordova-plugin-statusbar",
        "cordova-plugin-splashscreen",
        "cordova-plugin-console",
        "ionic-plugin-keyboard"
    ],
    "cordovaPlatforms": [],
    "description": "Juks",
    "cordova": {
        "platforms": [
            "browser"
        ],
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "cordova-sqlite-storage": {},
            "ionic-plugin-keyboard": {}
        }
    }

And myconfig.xml

    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="http://ionic.local/*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="loadUrlTimeoutValue" value="700000" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <preference name="Orientation" value="portrait" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="16" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <feature name="StatusBar">
        <param name="ios-package" onload="true" value="CDVStatusBar" />
    </feature>
    <engine name="browser" spec="^4.1.0" />
    <plugin name="cordova-plugin-console" spec="^1.0.5" />
    <plugin name="cordova-plugin-device" spec="^1.1.4" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
    <plugin name="cordova-plugin-statusbar" spec="^2.2.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
    <plugin name="cordova-sqlite-storage" spec="^2.0.4" />
    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />

Thanks guys ;)

Servuc commented 7 years ago

Hello,

Very stupid thing ....

Solution

The --variable isn't here for some useless thing :

cordova plugin add cordova-plugin-photo-library --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="To choose photos" --save

Perhaps, some moderator should write how is VERY important on README :)

Have a good day