LoginSignup
4
2

More than 1 year has passed since last update.

【Flutter】デバイスの設定画面へ遷移する

Last updated at Posted at 2022-11-11

要件

アプリからOSの設定画面へ遷移したい

SDK

既存のSDKで実現できるかを調べてみました。
下記のSDKでOSのアプリ設定画面が開けます。

  • permission_handler
  • app_settings
    permission_handlerについて、iOSとAndroidともOSのアプリを開けます。
    サンプルソースは下記です。
import 'package:permission_handler/permission_handler.dart';

TextButton(
  onPressed: () async {
    openAppSettings();
  },
  style: TextButton.styleFrom(
    primary: Colors.blue,
  ),
  child: Text('設定を開く'),
),

app_settingsについて、下記の遷移画面が用意されていますが、Android側が通常動作できますが、iOS側について、アップル社の規定により、メイン設定画面へ遷移することしか許されてないようです。詳細は下記のgithubのissuesにも掲載されています。app_settings

  • openAppSettings
  • openWIFISettings
  • openLocationSettings
  • openSecuritySettings
  • openBluetoothSettings
  • openDataRoamingSettings
  • openDateSettings
  • openDisplaySettings
  • openNotificationSettings
  • openSoundSettings
  • openInternalStorageSettings
  • openBatteryOptimizationSettings
  • openDevelopmentSettings
      ElevatedButton(
        child: Text("Location"),
        onPressed: () {
          AppSettings.openLocationSettings();
        },
      ),

Method Channel

iOS

iOSの場合、上記のSDKを使うとOSの対象アプリの設定画面へ遷移してしまうため、メイン設定画面へ遷移したい場合は下記の方法で遷移できる

  • method channelの作成
    /ios/Runner/AppDelegate.swift
    上記ファイルに下記のソースを追加することで、iOSで設定画面へ遷移することが可能です。
    ※App-Prefs:root=***子メニューまでやったら、アップル審査にリジェクトされるそうです。

Guideline 2.5.1 - Performance - Software Requirements 

Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.

Specifically, your app uses the following non-public URL scheme:

app-prefs:root=notifications_id&path=

Next Steps

To resolve this issue, please revise your app to provide the associated functionality using public APIs or remove the functionality using the "prefs:root" or "App-Prefs:root" URL scheme.


    GeneratedPluginRegistrant.register(with: self)
    // 追加start
    let methodChannelName = "openSetting"
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    let settingsChannel = FlutterMethodChannel(name: methodChannelName, binaryMessenger: controller as! FlutterBinaryMessenger)

    // MethodChannelからのメッセージを受け取ります
    settingsChannel.setMethodCallHandler({
      (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
      if (call.method == "openSetting") {
        let url = URL(string: "App-Prefs:root")
        let app = UIApplication.shared
        result(app.openURL(url!))
      } else {
        result(FlutterMethodNotImplemented)
      }
    })
    // 追加end
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)

  • 呼び出し
const channel = MethodChannel("openSetting");
channel.invokeMethod('openSetting');

参考

4
2
0

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
4
2