Skip to content

πŸ“± Bridge for requesting state from an iOS device

License

Notifications You must be signed in to change notification settings

CandyCoded/Unity-iOS-Bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Unity iOS Bridge

Installation

Unity Package Manager

{
  "dependencies": {
    "com.candycoded.unity-ios-bridge": "https://github.com/CandyCoded/Unity-iOS-Bridge.git#v1.1.0"
  }
}

Contents

Documentation

Accessibility

Make your apps accessible to everyone, including people with disabilities.

https://developer.apple.com/documentation/uikit/accessibility?language=objc

IOSUIAccessibilityIsAssistiveTouchRunning

Returns a Boolean value indicating whether the system preference for AssistiveTouch is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsAssistiveTouchRunning()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1648479-uiaccessibilityisassistivetouchr?language=objc

IOSUIAccessibilityIsVoiceOverRunning

Returns a Boolean value indicating whether VoiceOver is running.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsVoiceOverRunning()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615187-uiaccessibilityisvoiceoverrunnin?language=objc

IOSUIAccessibilityIsSwitchControlRunning

Returns a Boolean value indicating whether Switch Control is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsSwitchControlRunning()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615131-uiaccessibilityisswitchcontrolru?language=objc

IOSUIAccessibilityIsShakeToUndoEnabled

Returns a Boolean value indicating whether the system preference for Shake to Undo is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsShakeToUndoEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615103-uiaccessibilityisshaketoundoenab?language=objc

IOSUIAccessibilityIsClosedCaptioningEnabled

Returns a Boolean value indicating whether closed captioning is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsClosedCaptioningEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615112-uiaccessibilityisclosedcaptionin?language=objc

IOSUIAccessibilityIsBoldTextEnabled

Returns a Boolean value indicating whether bold text is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsBoldTextEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615156-uiaccessibilityisboldtextenabled?language=objc

IOSUIAccessibilityDarkerSystemColorsEnabled

Returns a Boolean value indicating whether darken colors is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityDarkerSystemColorsEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615087-uiaccessibilitydarkersystemcolor?language=objc

IOSUIAccessibilityIsGrayscaleEnabled

Returns a Boolean value indicating whether grayscale is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsGrayscaleEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615189-uiaccessibilityisgrayscaleenable?language=objc

IOSUIAccessibilityIsGuidedAccessEnabled

Returns a Boolean value indicating whether the app is running in Guided Access mode.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsGuidedAccessEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615173-uiaccessibilityisguidedaccessena?language=objc

IOSUIAccessibilityIsInvertColorsEnabled

Returns a Boolean value indicating whether inverted colors is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsInvertColorsEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615167-uiaccessibilityisinvertcolorsena?language=objc

IOSUIAccessibilityIsMonoAudioEnabled

Returns a Boolean value indicating whether system audio is set to mono.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsMonoAudioEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615123-uiaccessibilityismonoaudioenable?language=objc

IOSUIAccessibilityIsReduceMotionEnabled

Returns a Boolean value indicating whether reduce motion is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsReduceMotionEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615133-uiaccessibilityisreducemotionena?language=objc

IOSUIAccessibilityIsReduceTransparencyEnabled

Returns a Boolean value indicating whether reduce transparency is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsReduceTransparencyEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615074-uiaccessibilityisreducetranspare?language=objc

IOSUIAccessibilityIsSpeakScreenEnabled

Returns a Boolean value indicating whether speaking the screen is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsSpeakScreenEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615109-uiaccessibilityisspeakscreenenab?language=objc

IOSUIAccessibilityIsSpeakSelectionEnabled

Returns a Boolean value indicating whether speaking the selection is enabled.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Accessibility.IOSUIAccessibilityIsSpeakSelectionEnabled()); // true
#endif

Ref: https://developer.apple.com/documentation/uikit/1615154-uiaccessibilityisspeakselectione?language=objc

Alerts

IOSUIAlertController

#if UNITY_IOS && !UNITY_EDITOR
	CandyCoded.UnityIOSBridge.Alert.IOSUIAlertController("Title", "message", () => { Debug.Log("OK"); });
#endif
#if UNITY_IOS && !UNITY_EDITOR
	CandyCoded.UnityIOSBridge.Alert.IOSUIAlertController("Title", "message", () => { Debug.Log("OK"); }, () => { Debug.Log("Cancel"); });
#endif

Permission

IOSPermissionCameraOK

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Permission.IOSPermissionCameraOK()); // true
#endif

Ref: https://developer.apple.com/documentation/avfoundation/avauthorizationstatus?language=objc

Photos

IOSImageAddToGallery

Note: This requires NSPhotoLibraryAddUsageDescription to be in the Info.plist file with a value.

Note: Screenshot.Save uses the internal method ScreenCapture.CaptureScreenshot which returns before the file is saved to the device. Make sure the file exists before calling IOSImageAddToGallery by using a coroutine to wait until the file exists.

public void TakeScreenshot()
{

    StartCoroutine(TakeScreenshotCoroutine());

}

private static IEnumerator TakeScreenshotCoroutine()
{

    var screenshotFilePath = Screenshot.Save();

    Debug.Log($"Saved screenshot to {screenshotFilePath}");

    while (!File.Exists(screenshotFilePath))
    {

        yield return null;

    }

    yield return new WaitForEndOfFrame();

#if UNITY_IOS && !UNITY_EDITOR
    CandyCoded.UnityIOSBridge.Photos.IOSImageAddToGallery(screenshotFilePath);
    Debug.Log("Saved to gallery.");
#endif

}

Ref: https://developer.apple.com/documentation/bundleresources/information_property_list/nsphotolibraryaddusagedescription?language=objc Ref: https://developer.apple.com/documentation/bundleresources/information_property_list/uifilesharingenabled?language=objc

Settings

IOSIsLowPowerModeEnabled

A Boolean indicating whether Low Power Mode is enabled on an iOS device.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.Settings.IOSIsLowPowerModeEnabled()); // false
#endif

Ref: https://developer.apple.com/documentation/foundation/nsprocessinfo/1617047-lowpowermodeenabled?language=objc

IOSUIImpactFeedbackGenerator

#if UNITY_IOS && !UNITY_EDITOR
CandyCoded.UnityIOSBridge.Settings.IOSUIImpactFeedbackGenerator();
#endif
#if UNITY_IOS && !UNITY_EDITOR
CandyCoded.UnityIOSBridge.Settings.IOSUIImpactFeedbackGenerator("light");
CandyCoded.UnityIOSBridge.Settings.IOSUIImpactFeedbackGenerator("medium");
CandyCoded.UnityIOSBridge.Settings.IOSUIImpactFeedbackGenerator("heavy");
#endif

Ref: https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator?language=objc

View

IOSSafeAreaInsets

The insets that you use to determine the safe area for this view.

#if UNITY_IOS && !UNITY_EDITOR
Debug.Log(CandyCoded.UnityIOSBridge.View.IOSSafeAreaInsets()); // {top: 0, left: 0, right: 0, bottom: 0}
#endif

Ref: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc