Skip to main content

Platform

isPlatform​

isPlatform メソッドを使用して、アプリが特定のプラットフォームで実行されているかどうかを確認できます:

import { isPlatform } from '@ionic/vue';

isPlatform('ios'); // returns true when running on a iOS device

isPlatform(platformName) は、アプリが動作しているプラットフォームに応じて true または false を返します。同じアプリでも複数のプラットフォーム名に対して true を返すことがあります。たとえば iPad 上のアプリでは、mobile、ios、ipad、tablet が true になります。Cordova 上で動作していれば、cordova も true になります。

getPlatforms​

getPlatforms メソッドを使用して、アプリが現在実行されているプラットフォームを判別できます。

import { getPlatforms } from '@ionic/vue';

getPlatforms(); // returns ["iphone", "ios", "mobile", "mobileweb"] from an iPhone

デバイスによっては getPlatforms が複数の値を返します。これらの値はプラットフォームの階層を表します。たとえば iPhone では mobile、ios、iphone が返されます。

Platforms​

次の表に、使用可能なすべてのプラットフォーム値とその説明を示します。

Platform NameDescription
androidAndroid を搭載したデバイスです。
capacitorCapacitor を実行しているデバイス
cordovaCordova を実行しているデバイス
desktopa desktop device
electronElectron を使っているデスクトップデバイスです。
hybridCapacitor または Cordova を実行しているデバイス
iosiOS を搭載したデバイスです。
ipadan iPad device
iphonean iPhone device
mobilea mobile device
mobilewebモバイルデバイス上で動作するウェブブラウザ
phableta phablet device
pwaa PWA app
tableta tablet device

プラットフォーム検出機能のカスタマイズ​

特定のプラットフォームを検出する関数は、グローバルな Ionic config に別の関数を指定して上書きできます。各関数は引数に window を取り、真偽値を返します。

createApp(App).use(IonicVue, {
platform: {
/** The default `desktop` function returns false for devices with a touchscreen.
* This is not always wanted, so this function tests the User Agent instead.
**/
desktop: (win) => {
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(win.navigator.userAgent);
return !isMobile;
},
},
});
type PlatformConfig = {
android?: ((win: Window) => boolean) | undefined;
capacitor?: ((win: Window) => boolean) | undefined;
cordova?: ((win: Window) => boolean) | undefined;
desktop?: ((win: Window) => boolean) | undefined;
electron?: ((win: Window) => boolean) | undefined;
hybrid?: ((win: Window) => boolean) | undefined;
ios?: ((win: Window) => boolean) | undefined;
ipad?: ((win: Window) => boolean) | undefined;
iphone?: ((win: Window) => boolean) | undefined;
mobile?: ((win: Window) => boolean) | undefined;
mobileweb?: ((win: Window) => boolean) | undefined;
phablet?: ((win: Window) => boolean) | undefined;
pwa?: ((win: Window) => boolean) | undefined;
tablet?: ((win: Window) => boolean) | undefined;
};