我们可以在 Ionic 框架中仅为 iOS 编写单独的代码吗?



我需要一段代码来运行,以便在由Ionic框架制作的混合应用程序中仅为iOS运行。我该怎么做?

我们使用适用于iOS,Android,Windows和Blackberry的混合应用程序。我需要实现这样的条件,其中我的部分代码仅适用于 iOS,而不适用于 Android 或任何其他平台。

我怎样才能做到这一点?

ionic offer platform API

https://ionicframework.com/docs/api/platform/Platform/

例子是

import { Platform } from 'ionic-angular';
@Component({...})
export MyPage {
  constructor(public plt: Platform) {
    if (this.plt.is('ios')) {
      // This will only print when on iOS
//your code here
      console.log('I am an iOS device!');
    }
  }
}

最新更新