Implement App Tracking Transparency for Ionic Angular and Cordova iOS app

How to use the https://github.com/chemerisuk/cordova-plugin-idfa plugin in Ionic v3.

I had some issues using the example provided so I had to call the exec directly:

// first install the plugin
// cordova plugin add cordova-plugin-idfa
// npm i cordova-plugin-idfa --save

// add permissions to config.xml under ios platform
<platform name="ios">
    <edit-config target="NSUserTrackingUsageDescription" file="*-Info.plist" mode="merge">
        <string> My tracking usage description </string>
    </edit-config>
</platform>

// has to be called after platform is ready
// this.platform.ready().then(() => {}

askTrackingPermission() {
    if (this.platform.is('cordova') && this.platform.is('ios')) {

      if (window.cordova) {
        console.log('trying to request permission ');
        window.cordova.exec(win, fail, 'idfa', "requestPermission", []);
      }
    }

    function win(res) {
      console.log('success ' + JSON.stringify(res));
    }
    function fail(res) {
      console.log('fail ' + JSON.stringify(res));
    }
  }

readTrackingPermission() {

    if (this.platform.is('cordova') && this.platform.is('ios')) {

      if (window.cordova) {
        window.cordova.exec(win, fail, 'idfa', "getInfo", []);
      }
    }

    function win(res) {
      console.log('success  ' + JSON.stringify(res));
    }
    function fail(res) {
      console.log('fail ' + JSON.stringify(res));
    }
  }

Also, you can only test this from the iOS simulator (or device) running 14.5.1+ iOS. In your iOS device settings check privacy->tracking (setting) it has to be allowed to ask. And you will only be able to ask the user once.

Good luck!

How to Open PDF/File in Ionic on Android

How to Open PDF/File in Ionic on Android?

If you recently tried to open a file in Ionic from the application dir using `fileOpener2` plugin you may have encountered an error `File Not Found` which could indicate permission error.

It turns out you can’t open a file from `applicationDirectory` directly, you have to copy it into another directory:

if (this.platform.is('android')) {
  const self = this;
  const targetFile = self.file.dataDirectory + '/' + yourFileName;
		
  self.file.copyFile(self.file.applicationDirectory + 'www/assets/', yourFileName, 
                     self.file.dataDirectory, yourFileName).
           then(function (res) {
	     self.fileOpener.open(targetFile, 'application/pdf');
	});
}

Install the Cordova Plugin here:

https://github.com/pwlin/cordova-plugin-file-opener2
https://ionicframework.com/docs/native/file-opener

How To Create Downloadable CSV File in JS/Angular

 
import { SecurityContext } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
private sanitizer: DomSanitizer;

downloadCSV() {

  let blob = new Blob([yourdata], { type: 'text/csv' });
  let urlPath = this.sanitizer.sanitize(SecurityContext.URL,
this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob)));
    
  let tempLink = document.createElement('a');
  tempLink.href = urlPath;
  tempLink.setAttribute('download', 'download.csv');
  tempLink.click();
}
      

How Much Access Does Facebook App Have?

These are the permissions Facebook app has on Android devices:

Device & app history:

Retrieve running apps

Storage:

– read the contents of your USB storage
– modify or delete the contents of your USB storage

Location:

– approximate location (network-based)
– precise location (GPS and network-based)

Phone:

– write call log
– read phone status and identity
– read call log
– directly call phone numbers

Microphone:

– record audio

Identity:

– add or remove accounts
– read your own contact card
– find accounts on the device

Wi-Fi connection information

– view Wi-Fi connections

SMS:

– read your text messages (SMS or MMS)

Calendar:

– add or modify calendar events and send email to guests without owners’ knowledge
– read calendar events plus confidential information

Contacts:

– read your contacts
– modify your contacts
– find accounts on the device

Device ID & call information:

– read phone status and identity

Photos/Media/Files:

– read the contents of your USB storage
– modify or delete the contents of your USB storage

Camera:

– take pictures and videos

Other:

download files without notification
receive data from Internet
adjust your wallpaper size
control Near Field Communication
create accounts and set passwords

toggle sync on and off
view network connections
send sticky broadcast
change your audio settings
set wallpaper

reorder running apps
modify system settings
read sync settings
install shortcuts
prevent device from sleeping
connect and disconnect from Wi-Fi

pair with Bluetooth devices
run at startup
read battery statistics
full network access
control vibration

expand/collapse status bar
access Bluetooth settings
draw over other apps
read Google service configuration
change network connectivity

How To Batch commands in .bat file on Windows

Using the && ^ operators we can batch different commands to be executed in windows command prompt.

// example file – test.bat

mkdir newdir && ^
rd /s /q somefolder/otherfolder && ^
rd /s /q difffolder/otherfolder

Using only a single & symbol will make the following command execute even if the current one fails.
Also this is a good example of how to delete folders in a quick efficient way.

Google Android Play Store Target API Requirement Change

From Google:

Hello Google Play Developer,

This is a reminder that starting November 1, 2019, updates to apps and games on Google Play will be required to target Android 9 (API level 28) or higher. After this date, the Play Console will prevent you from submitting new APKs with a targetSdkVersion less than 28.

Configuring your app to target a recent API level ensures that users benefit from significant security and performance improvements, while still allowing your app to run on older Android versions (down to the minSdkVersion).

Android 9 (API level 28) introduces a number of changes to the Android system. The following behavior changes apply exclusively to apps that are targeting API level 28 or higher. Apps that set targetSdkVersion to API level 28 or higher must modify their apps to support these behaviors properly, where applicable to the app.

To target the api in your Cordova app set these min and target version in config.xml

    <preference name="android-minSdkVersion" value="23" />
    <preference name="android-targetSdkVersion" value="28" />