Mobile API
이 콘텐츠는 아직 번역되지 않았습니다.
Native mobile capabilities are exposed two ways:
- Per-platform managers —
application.IOS(in//go:build iosfiles) andapplication.Android(in//go:build androidfiles). Use these for anything platform-specific. See the iOS and Android references for the full per-platform surface. application.Mobile— a single, build-guarded manager covering the subset of capabilities that behave identically on both platforms. Use this when you want one code path that compiles and runs everywhere.
application.Mobile
Section titled “application.Mobile”application.Mobile dispatches to IOS on iOS, to Android on Android, and to
a no-op stub on desktop. Because it has no build constraint, you can call it from
ordinary, platform-agnostic Go — no //go:build files of your own:
// Works in any file, on any target.// On desktop this returns "" (no-op); on device it returns the real path.dbDir := application.Mobile.StoragePath()if dbDir == "" { // Off-device, or the directory could not be created — handle accordingly. return}db, _ := sql.Open("sqlite", filepath.Join(dbDir, "app.db"))StoragePath() returns the absolute path to the app’s private files directory —
getFilesDir() on Android, the Application Support directory on iOS — the
recommended home for databases and other persistent files. It returns an empty
string on desktop, and on device if the directory is unavailable (on iOS, if it
cannot be created), so check for "" before using it.
Capabilities
Section titled “Capabilities”The Mobile manager exposes the capabilities whose signatures are identical on
iOS and Android:
| Capability | API | Notes |
|---|---|---|
| Share sheet | Mobile.Share(json) | {text, url} |
| Open URL externally | Mobile.OpenURL(url) | System browser |
| Keep screen awake | Mobile.SetKeepAwake(bool) | |
| Torch / flashlight | Mobile.SetTorch(bool) | → common:torch |
| Safe-area insets | Mobile.SafeAreaJSON() | {top,bottom,left,right} |
| App info | Mobile.AppInfoJSON() | {name,version,build,bundleId} |
| Orientation lock | Mobile.SetOrientation(mode) | portrait / landscape / auto |
| Status bar | Mobile.SetStatusBar(json) | style + visibility |
| Storage info | Mobile.StorageJSON() | {free,total} bytes |
| Storage path | Mobile.StoragePath() | App-private files directory |
| Power / battery | Mobile.PowerJSON() | {level,charging,lowPower} |
| Network status | Mobile.NetworkJSON() | {connected,type} |
| Biometrics | Mobile.BiometricAuthenticate(reason) | → common:biometric |
| Secure storage | Mobile.SecureGet(key) / Mobile.SecureDelete(key) | Keychain / EncryptedSharedPreferences |
| Geolocation | Mobile.GetLocation() | one-shot → common:location |
| Haptics | Mobile.Haptic(type) | impact / notification / selection |
| Accelerometer | Mobile.SetMotion(bool) | → common:motion |
| Proximity | Mobile.SetProximity(bool) | → common:proximity |
| Text-to-speech | Mobile.Speak(text) / Mobile.StopSpeak() | |
| Keyboard insets | Mobile.SetKeyboardWatch(bool) | → common:keyboard |
| Screen-capture | Mobile.SetScreenProtect(bool) | → common:screenCapture |
| Camera | Mobile.CapturePhoto() / Mobile.CaptureVideo() | → common:capture |
Asynchronous results arrive as common:* events, exactly as with the
per-platform managers — see Events for the payloads.
What stays platform-specific
Section titled “What stays platform-specific”Capabilities that differ in shape between iOS and Android are not on
Mobile; call them through application.IOS / application.Android from a
build-tagged file:
| Concern | iOS | Android |
|---|---|---|
| Brightness (set) | IOS.SetBrightness(0.0-1.0) | Android.SetBrightness(0-100) |
| Brightness / orientation (get) | IOS.GetBrightness() / IOS.GetOrientation() | Android.BrightnessJSON() / Android.OrientationJSON() |
| Local notification | IOS.PostNotification(json) | Android.Notify(json) |
| Secure store (write) | IOS.SecureSet(key, value) | Android.SecureSet(json) |
| Background execution | IOS.BeginBackgroundTask / EndBackgroundTask | Android.StartForegroundService / StopForegroundService |