capacitor-community / privacy-screen

⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
MIT License
88 stars 23 forks source link

bug: "PrivacyScreen" plugin is not implemented on ios Error on enable() #72

Closed jkyoutsey closed 1 year ago

jkyoutsey commented 1 year ago

Plugin version: ^4.2.0

Platform(s): iOS simulator, Ionic, Nx

Current behavior: In Simulator I see the following error reported when I call PrivacyScreen.enable():

⚡️  [error] - ERROR Error: Uncaught (in promise): Error: "PrivacyScreen" plugin is not implemented on ios
CapacitorException@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:430:10
createPluginMethod@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:522:37
@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:529:40
onInvoke@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:56128:31
run@capacitor://mobile.medstudy.com/polyfills.a148d1210cad8805.js:132:43
@capacitor://mobile.medstudy.com/polyfills.a148d1210cad8805.js:1212:31
onInvokeTask@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:55808:32
onInvokeTask@capacitor://mobile.medstudy.com/vendor.62e464336713e827.js:56117:35
runTask@capacitor://mobile.medstudy.com/polyfills.a148d1210cad8805.js:178:49
drainMicroTaskQueue@capacitor://mobile.medstudy.com/polyfills.a148d1210cad8805.js:549:30

Expected behavior: PrivacyScreen.enable() should not throw errors on iOS

Steps to reproduce: Call PrivacyScreen.enable().

Related code: Using a simple Angular service to enable/disable:

import { Injectable } from '@angular/core';
import { PrivacyScreen } from '@capacitor-community/privacy-screen';
import { Logger } from '@ms/shared/utils';

@Injectable({
    providedIn: 'root',
})
export class PreventScreenshotService {
    private readonly CLASS_NAME = 'PreventScreenshotService';

    async preventScreenshots() {
        Logger.info(this.CLASS_NAME, 'preventScreenshots', `Screenshots are disabled.`);
        await PrivacyScreen.enable();
    }

    async allowScreenshots() {
        Logger.info(this.CLASS_NAME, 'allowScreenshots', `Screenshots are enabled.`);
        await PrivacyScreen.disable();
    }
}

Other information: I'm in an Nx repo with an Ionic application.

My apps/my-app/ios/App/App/capacitor.config.json has this configuration.

    "plugins": {
        "PrivacyScreen": {
            "enable": false,
            "imageName": "Splashscreen"
        }
    },

My apps/my-app/package.json has the plugin listed:

{
    "name": "my-app",
    "devDependencies": {
        "@capacitor/cli": "^5.0.3",
        "@capacitor/app": "../../node_modules/@capacitor/app",
        "@capacitor/ios": "../../node_modules/@capacitor/ios",
        "@capacitor/android": "../../node_modules/@capacitor/android",
        "@capacitor/network": "../../node_modules/@capacitor/network",
        "@capacitor/splash-screen": "../../node_modules/@capacitor/splash-screen",
        "@capacitor-community/privacy-screen": "../../node_modules/@capacitor-community/privacy-screen"
    }
}

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.4.1
  @capacitor/core: 5.4.1
  @capacitor/android: 5.4.1
  @capacitor/ios: 5.4.1

Installed Dependencies:

  @capacitor/cli: 5.0.5
  @capacitor/core: 5.0.5
  @capacitor/android: 5.0.5
  @capacitor/ios: 5.0.5

[success] iOS looking great! 👌
robingenz commented 1 year ago

Thank you for your request. Please provide a Minimal, Reproducible Example in a public GitHub repository so I can debug the issue.

jkyoutsey commented 1 year ago

This was a bug on my end. In Nx + ionic the cap add isn't adding plugins to the includePlugins array in the app's capacitor.config.