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

Thread 1: EXC_BAD_ACCESS (code=2, address=0x16ba47fd0) #64

Closed balaji-sasikumar closed 1 year ago

balaji-sasikumar commented 1 year ago

Plugin version:

"@capacitor-community/privacy-screen": "^4.1.1",

Platform(s):

in ios

Current behavior:

The app crashes with the "EXC_BAD_ACCESS" error as described above when certain events related to the "privacy-screen" package occur.

Expected behavior The app should operate smoothly without any crashes or errors after installing the "@capacitor-community/privacy-screen" package.

Steps to reproduce:

1.Install the "@capacitor-community/privacy-screen" package in the project using npm or yarn. 2.Integrate the package into the app according to the documentation provided by the package. 3.Run the app on a device or simulator. 4.Perform actions that trigger the events related to the "privacy-screen" package, such as going to the background or returning to the foreground.

Capacitor doctor:

💊 Capacitor Doctor 💊

Latest Dependencies:

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

Installed Dependencies:

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

[success] iOS looking great! 👌 [success] Android looking great!

robingenz commented 1 year ago

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

balaji-sasikumar commented 1 year ago

After installing the "@capacitor-community/privacy-screen" package and following the provided steps to enable it in the "capacitor.config.json" and "capacitor.config.ts" files, I built the app and installed it on my iPhone 13 Pro. However, as soon as I put the app into the background by pressing the home button or switching to another app, the app crashed with the "Thread 1: EXC_BAD_ACCESS" exception in the "AppDelegate.swift" file at the line where the class is defined:

class AppDelegate: UIResponder, UIApplicationDelegate {

exception-privacy-screen

This issue occurred consistently after enabling the "PrivacyScreen" plugin, and I couldn't find any direct cause for the crash. I checked for any conflicts with other plugins or native code, but the crash seemed to be isolated to the "PrivacyScreen" plugin.

As this exception significantly impacts the stability of the app, I kindly request support from the community to investigate the root cause and find a resolution. I am willing to provide any additional information or logs required for debugging purposes. Any assistance in resolving this critical issue would be highly appreciated. Thank you.

robingenz commented 1 year ago

As i said, please provide a Minimal, Reproducible Example using this template in a public GitHub repository so I can debug the issue.

ArbiCap-Jordy commented 1 year ago

Got exactly the same problem and tried in a fresh project, same issue.

package.json

{ "name": "fresh", "version": "0.0.1", "author": "Ionic Framework", "homepage": "https://ionicframework.com/", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test", "lint": "ng lint" }, "private": true, "dependencies": { "@angular/animations": "^16.0.0", "@angular/common": "^16.0.0", "@angular/compiler": "^16.0.0", "@angular/core": "^16.0.0", "@angular/forms": "^16.0.0", "@angular/platform-browser": "^16.0.0", "@angular/platform-browser-dynamic": "^16.0.0", "@angular/router": "^16.0.0", "@capacitor-community/privacy-screen": "^4.1.1", "@capacitor/app": "5.0.6", "@capacitor/core": "5.2.2", "@capacitor/haptics": "5.0.6", "@capacitor/ios": "5.2.2", "@capacitor/keyboard": "5.0.6", "@capacitor/status-bar": "5.0.6", "@ionic/angular": "^7.0.0", "ionicons": "^7.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.13.0" }, "devDependencies": { "@angular-devkit/build-angular": "^16.0.0", "@angular-eslint/builder": "^16.0.0", "@angular-eslint/eslint-plugin": "^16.0.0", "@angular-eslint/eslint-plugin-template": "^16.0.0", "@angular-eslint/schematics": "^16.0.0", "@angular-eslint/template-parser": "^16.0.0", "@angular/cli": "^16.0.0", "@angular/compiler": "^16.0.0", "@angular/compiler-cli": "^16.0.0", "@angular/language-service": "^16.0.0", "@capacitor/cli": "5.2.2", "@ionic/angular-toolkit": "^9.0.0", "@types/jasmine": "~4.3.0", "@types/node": "^12.11.1", "@typescript-eslint/eslint-plugin": "5.3.0", "@typescript-eslint/parser": "5.3.0", "eslint": "^7.26.0", "eslint-plugin-import": "2.22.1", "eslint-plugin-jsdoc": "30.7.6", "eslint-plugin-prefer-arrow": "1.2.2", "jasmine-core": "~4.6.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", "karma-coverage": "~2.2.0", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", "ts-node": "^8.3.0", "typescript": "~5.0.2" }, "description": "An Ionic project" }

The only thing I did here is to enable the plugin in the app.component.ts

import { Component } from '@angular/core';
import { PrivacyScreen } from '@capacitor-community/privacy-screen';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor() {

  }

  initApp(){
    // ++++++++++++++++++++++++
    // Setup Privacy Screen
    // ++++++++++++++++++++++++
    PrivacyScreen.addListener('screenRecordingStarted', () => {
      // Your code to execute when the screen recording starts
    });
    PrivacyScreen.addListener('screenshotTaken', () => {
      // Your code to execute when the screen recording starts
    });
    PrivacyScreen.enable();
  }
}
saravanapriyanm commented 1 year ago

We are also experiencing same issue.

benluria commented 1 year ago

We are experiencing the same issue. Steps to reproduce:

RishikeshB commented 1 year ago

experiencing the same issue , while enable PrivacyScreen on a page and running the app on background within 8-10 sec the app crashed with the "Thread 1: EXC_BAD_ACCESS" exception in the "AppDelegate.swift"

godhand1607 commented 1 year ago

++ also getting this error

UPDATE: It seems to only happen if PrivacyScreen is enabled at startup

benluria commented 1 year ago

++ also getting this error

UPDATE: It seems to only happen if PrivacyScreen is enabled at startup

I am experiencing the crash and it is disabled in CapacitorConfig. It is only enabled on specific pages. Example using Ionic Capacitor w/ Angular

capacitor.config.ts:

const config: CapacitorConfig = {
  plugins: {
    PrivacyScreen: {
      enable: false
    }
  }

component.ts file:

ionViewDidEnter() {
    if (Capacitor.isNativePlatform()) {
        PrivacyScreen.enable()
        .then(() => {
            console.log('privacy screen enabled');
        })
        .catch(err => console.error(err));
    }
  }
ArbiCap-Jordy commented 1 year ago

++ also getting this error

UPDATE: It seems to only happen if PrivacyScreen is enabled at startup

I tried this way and it was working for a while, but the crashes actually continue. It doesn't seem to solve the problem

robingenz commented 1 year ago

This issue is caused by the disable screenshots feature (see #59). Version 4.0.0 works. @dtarnawsky Any idea?

EDIT: Interesting fact: It works without problems if you enable the plugin twice (see #65).

dtarnawsky commented 1 year ago

Not sure why it is functioning this way now but adding 2 secure text fields seems to fix the problem so I've done that in the PR: https://github.com/capacitor-community/privacy-screen/pull/69

robingenz commented 1 year ago

Thanks @dtarnawsky! I will publish a new release.