Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

cordova - Using an ionic native plugin only on Android

I have an interesting use cases where I would like to use an ionic native plugin namely, bluetooth-serial only on one platform out of two. So I would like to use it on Android but not on iOS. Is there a way to add a dependency just to one platform ?

question from:https://stackoverflow.com/questions/66060255/using-an-ionic-native-plugin-only-on-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can use Platform Api to Detect platform and write your platform specific code.

in your .ts file:

import { Platform } from '@ionic/angular';

export class YourPage implements OnInit {
    constructor(private platform: Platform){
    }
  if (this.platform.is('android')) {
     // Write your Android Specific code
  } else {
     console.log('Other Platform')
  }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...