1
1

More than 3 years have passed since last update.

iOSとAndroidを区別するのに便利なJavaScript置いておくね

Posted at
var isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android');
var isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios');

これは基本的にユーザーエージェント(UA)を見て正規表現でandroidかiOSかを判別しています。UA &&の部分はnullチェックですね。UAの値を取得できなかった時にエラーで落ちないようにしています。

日本のスマホのシェアはAndroidとiOSが99%を占めているので上記以外はその他で例外処理をしてしまって良いでしょう。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1