Skip to content

Instantly share code, notes, and snippets.

@yaizudamashii
Created March 23, 2021 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaizudamashii/3a222c78ca3223ed2ce5e4b0b9e48157 to your computer and use it in GitHub Desktop.
Save yaizudamashii/3a222c78ca3223ed2ce5e4b0b9e48157 to your computer and use it in GitHub Desktop.
import Flutter
import UIKit
class PrivacySettingViewController: UIViewController {
static let channelName: String = "your.app.identifier/privacy" // これはグローバルで他とかぶらない名前をつけます
// other functions ...
private func createFlutterChannel(_ flutterViewController: FlutterViewController) {
let privacyChannel = FlutterMethodChannel(name: channelName, binaryMessenger: flutterViewController.binaryMessenger)
privacyChannel.setMethodCallHandler({ (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
guard call.method == "setPrivacyFlag" || call.method == "getPrivacyFlag" else {
result(FlutterMethodNotImplemented)
return
}
let privacyHandler = PrivacyHandler()
if call.method == "setPrivacyFlag" {
guard let isOn: Bool = (call.arguments as? [Any])?.first as? Bool else {
result(FlutterMethodNotImplemented)
return
}
privacyHandler.privacyFlag = isOn
result(isOn)
}
if call.method == "getPrivacyFlag" {
let isOn: Bool = privacyHandler.privacyFlag
result(isOn)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment