Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Check for ARKit support

Discussion in 'iOS and tvOS' started by nickfourtimes, Aug 2, 2017.

  1. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    212
    Is there a good way to check if an arbitrary iOS device supports ARKit? I've looked through UnityARSessionNativeInterface and couldn't see anything really obvious; for now, I'm using the following:

    Code (CSharp):
    1. try {
              
    2.     ARKitSessionConfiguration s1 = new ARKitSessionConfiguration ();
    3.     ARKitWorldTackingSessionConfiguration s2 = new ARKitWorldTackingSessionConfiguration ();
    4.     if (s1.IsSupported || s2.IsSupported) {
    5.         IsArKitSupported = true;
    6.     } else {
    7.         IsArKitSupported = false;
    8.     }
    9. } catch {
    10. }
    It feels like a bit of a hack though. Any alternatives are welcome!
     
  2. Wentao

    Wentao

    Joined:
    Mar 11, 2014
    Posts:
    6
    same question, currently the IsSupported only exist in ARKitSessionConfiguration and ARKitWorldTackingSessionConfiguration, but not exist in
    UnityARSessionNativeInterface
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    A preliminary test you can do is the os version (if not iOS 11, then ARKit not supported).
     
  4. Wentao

    Wentao

    Joined:
    Mar 11, 2014
    Posts:
    6
    but ios device before 6s will also have iOS11 later, this condition will not work then
     
  5. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    ARKit will still work on those older devices, it just won’t have position tracking (6 DOF).
     
  6. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Please refer to this documentation https://developer.apple.com/documentation/arkit

    Apple says you can put a requirement in your plist to ensure that your app only runs on ARKit capable devices, otherwise use the Configuration .IsSuppported methods to see if it is supported on the current device.
     
  7. mirostraka

    mirostraka

    Joined:
    Feb 17, 2014
    Posts:
    41
    this though doesn't work that well for me - but it is possible I'm messing things up. I've tested on a device that could run ARKit, but did not have iOS 11, which resulted in immediate crash. Currently I'm trying to do it like so, but with no success:
    Code (CSharp):
    1. iOSVersion = float.Parse(iOS.Device.systemVersion, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
    2. if(iOSVersion<11){
    3. //disable parent of all ARKit objects
    4. }
    5.  
    6. ARKitWorldTackingSessionConfiguration c = new ARKitWorldTackingSessionConfiguration();
    7. if(c.IsSupported==false){
    8. //disable parent of all ARKit objects
    9. }
    10. // otherwise start using ARKit
     
  8. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    What is your crash? Please give us as much information as you can. Your code snippet might be more helpful in the context of everything that is happening, but on it's own, it's not very helpful. A text file with your crash log would help.
     
  9. mirostraka

    mirostraka

    Joined:
    Feb 17, 2014
    Posts:
    41
    hey, thanks for getting back to me, here's what i've got:
    Code (CSharp):
    1. 2017-09-07 15:32:00.227809 EuclideanLands[503:204295] [DYMTLInitPlatform] platform initialization successful
    2. 2017-09-07 15:32:00.248404 EuclideanLands[503:204211] PlayerPrefsAutoSync: Loaded.
    3.  
    4. 2017-09-07 15:32:00.284996 EuclideanLands[503:204211] -> registered mono modules 0x100eb9990
    5. 2017-09-07 15:32:00.441984 EuclideanLands[503:204211] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
    6. -> applicationDidFinishLaunching()
    7. Player data archive not found at `/var/containers/Bundle/Application/3D394CF2-9D1D-404F-A7FE-E63D013D29C7/EuclideanLands.app/Data/data.unity3d`, using local filesystem2017-09-07 15:32:00.489862 EuclideanLands[503:204211] Metal GPU Frame Capture Enabled
    8. 2017-09-07 15:32:00.490099 EuclideanLands[503:204211] Metal API Validation Disabled
    9. 2017-09-07 15:32:00.825678 EuclideanLands[503:204211] PlayerPrefsAutoSync: iCloud Supported. Initializing.
    10. -> applicationDidBecomeActive()
    11. GfxDevice: creating device client; threaded=1
    12. Initializing Metal device caps: Apple A9X GPU
    13. Initialize engine version: 5.6.3f1 (d3101c3b8468)
    14. OnLevelWasLoaded was found on UnityARGeneratePlane
    15. This message has been deprecated and will be removed in a later version of Unity.
    16. Add a delegate to SceneManager.sceneLoaded instead to get notifications after scene loading has completed
    17. (Filename:  Line: 376)
    18.  
    19. OnLevelWasLoaded was found on AROnStart
    20. This message has been deprecated and will be removed in a later version of Unity.
    21. Add a delegate to SceneManager.sceneLoaded instead to get notifications after scene loading has completed
    22. (Filename:  Line: 376)
    23.  
    24. UnloadTime: 0.869458 ms
    25. Setting up 1 worker threads for Enlighten.
    26.  Thread -> id: 16f37b000 -> priority: 1
    27. 2017-09-07 15:32:03.412198 EuclideanLands[503:204211] PlayerPrefsAutoSync: Sending to iCloud
    28. Unloading 8 Unused Serialized files (Serialized files now loaded: 0)
    29. UnloadTime: 2.413625 ms
    30. FormatException: Unknown char: .
    31.  at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider, Boolean tryParse, Double& result, System.Exception& exc) [0x00000] in <filename unknown>:0
    32.  at System.Single.Parse (System.String s, IFormatProvider provider) [0x00000] in <filename unknown>:0
    33.  at AROnStart.Awake () [0x00000] in <filename unknown>:0
    34. (Filename: currently not available on il2cpp Line: -1)
    35.  
    36.  
    37. Unloading 13 unused Assets to reduce memory usage. Loaded Objects now: 691.
    38. Total: 0.401833 ms (FindLiveObjects: 0.049875 ms CreateObjectMapping: 0.015458 ms MarkObjects: 0.304000 ms  DeleteObjects: 0.031875 ms)
    39.  
    40. 2017-09-07 15:32:05.456330 EuclideanLands[503:204211] Uncaught exception: ARKitNotSupportedException: ARKit is not supported in the runtime you are using.  Make sure you are using a compatible device and or OS version
    41. (
    42.    0   CoreFoundation                      0x000000019337a1d8 <redacted> + 148
    43.    1   libobjc.A.dylib                     0x0000000191db455c objc_exception_throw + 56
    44.    2   CoreFoundation                      0x000000019337a108 <redacted> + 0
    45.    3   EuclideanLands                      0x00000001004b9ee8 unity_CreateNativeARSession + 72
    46.    4   EuclideanLands                      0x00000001000aba98 UnityARSessionNativeInterface__ctor_m3996903657 + 116
    47.    5   EuclideanLands                      0x00000001000ae2e0 UnityARSessionNativeInterface_GetARSessionNativeInterface_m2987304195 + 108
    48.    6   EuclideanLands                      0x00000001000a5698 UnityARCameraManager_Start_m1323027489 + 108
    49.    7   EuclideanLands                      0x000000010048d2cc _Z31RuntimeInvoker_Void_t1841601450PK10MethodInfoPvPS2_ + 28
    50.    8   EuclideanLands                      0x0000000100db8010 _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 68
    51.    9   EuclideanLands                      0x00000001007ec14c _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 100
    52.    10  EuclideanLands                      0x00000001007e4d88 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 60
    53.    11  EuclideanLands                      0x00000001008d0b40 _ZN13MonoBehaviour30InvokeMethodOrCoroutineCheckedE18ScriptingMethodPtr18ScriptingObjectPtrP21ScriptingExceptionPtr + 1216
    54.    12  EuclideanLands                      0x00000001008d0d54 _ZN13MonoBehaviour30InvokeMethodOrCoroutineCheckedE18ScriptingMethodPtr18ScriptingObjectPtr + 92
    55.    13  EuclideanLands                      0x00000001008cfaec _ZN13MonoBehaviour16DelayedStartCallEP6ObjectPv + 88
    56.    14  EuclideanLands                      0x0000000100609778 _ZN18DelayedCallManager6UpdateEi + 676
    57.    15  EuclideanLands                      0x0000000100711ad8 _Z10PlayerLoopv + 440
    58.    16  EuclideanLands                      0x000000010092fa80 _ZL19UnityPlayerLoopImplb + 32
    59.    17  EuclideanLands                      0x0000000100040614 UnityRepaint + 140
    60.    18  EuclideanLands                      0x0000000100040500 -[UnityAppController(Rendering) repaintDisplayLink] + 88
    61.    19  GPUToolsCore                        0x0000000102b8fb1c -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 176
    62.    20  QuartzCore                          0x00000001965801bc <redacted> + 44
    63.    21  QuartzCore                          0x0000000196580068 <redacted> + 444
    64.    22  IOKit                               0x00000001935e7138 IODispatchCalloutFromCFMessage + 372
    65.    23  CoreFoundation                      0x000000019331056c <redacted> + 180
    66.    24  CoreFoundation                      0x0000000193328934 <redacted> + 56
    67.    25  CoreFoundation                      0x00000001933280e8 <redacted> + 436
    68.    26  CoreFoundation                      0x0000000193325bcc <redacted> + 1840
    69.    27  CoreFoundation                      0x0000000193254048 CFRunLoopRunSpecific + 444
    70.    28  GraphicsServices                    0x0000000194cda198 GSEventRunModal + 180
    71.    29  UIKit                               0x00000001992392fc <redacted> + 684
    72.    30  UIKit                               0x0000000199234034 UIApplicationMain + 208
    73.    31  EuclideanLands                      0x000000010003a450 main + 160
    74.    32  libdyld.dylib                       0x00000001922385b8 <redacted> + 4
    75. )
    76. 2017-09-07 15:32:05.456780 EuclideanLands[503:204211] *** Terminating app due to uncaught exception 'ARKitNotSupportedException', reason: 'ARKit is not supported in the runtime you are using.  Make sure you are using a compatible device and or OS version'
    77. *** First throw call stack:
    78. (0x19337a1c0 0x191db455c 0x19337a108 0x1004b9ee8 0x1000aba98 0x1000ae2e0 0x1000a5698 0x10048d2cc 0x100db8010 0x1007ec14c 0x1007e4d88 0x1008d0b40 0x1008d0d54 0x1008cfaec 0x100609778 0x100711ad8 0x10092fa80 0x100040614 0x100040500 0x102b8fb1c 0x1965801bc 0x196580068 0x1935e7138 0x19331056c 0x193328934 0x1933280e8 0x193325bcc 0x193254048 0x194cda198 0x1992392fc 0x199234034 0x10003a450 0x1922385b8)
    79. libc++abi.dylib: terminating with uncaught exception of type NSException
    80. (lldb)
    81.  
     
  10. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    from the error, it looks like your UnityARCameraManager component is alive, and it tries to instantiate the UnityARSessionNativeInterface which will create the ARSession. You should probably have everything disabled on start, and then enable it if ARKit is supported. Not the other way around. Let me know if this helps.
     
  11. mirostraka

    mirostraka

    Joined:
    Feb 17, 2014
    Posts:
    41
    I don't know how I missed the fact that I can disable the objects and enable them if conditions are met, but managed to try so many obscure solutions. Thanks so much, will update here if it helps!
     
  12. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Here is my disabling of AR code that seems to work.

    Code (CSharp):
    1. public void Awake(){
    2.         // Turn off AR Camera if not supported
    3.         #if UNITY_IOS
    4.         Debug.Log("UnityEngine.iOS.Device.systemVersion:"+UnityEngine.iOS.Device.systemVersion);
    5.         float iOSVersion = 11f;
    6.         float.TryParse(UnityEngine.iOS.Device.systemVersion, out iOSVersion);
    7.         if(iOSVersion<11f){
    8.             Debug.Log("Less than 11");
    9.             disableAR();
    10.         }
    11.  
    12.         var gen = UnityEngine.iOS.Device.generation;
    13.         Debug.Log("gen:"+gen);
    14.        
    15.         if ( gen == UnityEngine.iOS.DeviceGeneration.iPhone4 ||
    16.             gen == UnityEngine.iOS.DeviceGeneration.iPhone4S ||
    17.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5 ||
    18.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5C ||
    19.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5S ||
    20.             gen == UnityEngine.iOS.DeviceGeneration.iPhone6 ||
    21.             gen == UnityEngine.iOS.DeviceGeneration.iPhone6Plus ||
    22.             gen == UnityEngine.iOS.DeviceGeneration.iPad1Gen ||
    23.             gen == UnityEngine.iOS.DeviceGeneration.iPad2Gen ||
    24.             gen == UnityEngine.iOS.DeviceGeneration.iPad3Gen ||
    25.             gen == UnityEngine.iOS.DeviceGeneration.iPad4Gen ||
    26.             gen == UnityEngine.iOS.DeviceGeneration.iPadAir1 ||
    27.             gen == UnityEngine.iOS.DeviceGeneration.iPadAir2 ||
    28.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini1Gen ||
    29.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini2Gen ||
    30.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini3Gen ||
    31.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini4Gen ||
    32.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch1Gen ||
    33.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch2Gen ||
    34.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch3Gen ||
    35.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch4Gen ||
    36.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch5Gen ||
    37.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch6Gen
    38.         ) {
    39.             Debug.Log("Device not supported");
    40.             disableAR();
    41.         }
    42.  
    43.         #endif
    44.     }
    45.  
    46.     private void disableAR(){
    47.         CameraController.cameraMain.gameObject.GetComponent<UnityARVideo>().enabled = false;
    48.         CameraController.cameraMain.gameObject.GetComponent<UnityARCameraNearFar>().enabled = false;
    49.         CameraController.cameraMain.clearFlags = CameraClearFlags.Skybox;
    50.         GameObject.Find("UnityARKit").SetActive(false);
    51.     }
     
    Last edited: Sep 16, 2017
  13. ZeN12

    ZeN12

    Joined:
    Mar 5, 2013
    Posts:
    10
    dentedpixel Doesn't work in part of checkin iOS version, because iOS version can be 11.0.0 and parsing will give the results 0. It requires to split string with separator '.' Here is my version:

    Code (CSharp):
    1.   private bool IsSupportedArKit()
    2.     {
    3.         #if UNITY_EDITOR
    4.         return true;
    5.         #endif
    6.  
    7.         #if UNITY_IOS
    8.         Debug.Log("UnityEngine.iOS.Device.systemVersion:" + UnityEngine.iOS.Device.systemVersion);
    9.         float iOSVersion = 11f;
    10.         string[] ver = UnityEngine.iOS.Device.systemVersion.Split('.');
    11.         float.TryParse(ver[0], out iOSVersion);
    12.         if (iOSVersion < 11f)
    13.         {
    14.             Debug.Log("Not supported iOS version: " + iOSVersion);
    15.             return false;
    16.         }
    17.  
    18.         var gen = UnityEngine.iOS.Device.generation;
    19.         Debug.Log("gen:" + gen);
    20.  
    21.         if (gen == UnityEngine.iOS.DeviceGeneration.iPhone4 ||
    22.             gen == UnityEngine.iOS.DeviceGeneration.iPhone4S ||
    23.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5 ||
    24.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5C ||
    25.             gen == UnityEngine.iOS.DeviceGeneration.iPhone5S ||
    26.             gen == UnityEngine.iOS.DeviceGeneration.iPhone6 ||
    27.             gen == UnityEngine.iOS.DeviceGeneration.iPhone6Plus ||
    28.             gen == UnityEngine.iOS.DeviceGeneration.iPad1Gen ||
    29.             gen == UnityEngine.iOS.DeviceGeneration.iPad2Gen ||
    30.             gen == UnityEngine.iOS.DeviceGeneration.iPad3Gen ||
    31.             gen == UnityEngine.iOS.DeviceGeneration.iPad4Gen ||
    32.             gen == UnityEngine.iOS.DeviceGeneration.iPadAir1 ||
    33.             gen == UnityEngine.iOS.DeviceGeneration.iPadAir2 ||
    34.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini1Gen ||
    35.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini2Gen ||
    36.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini3Gen ||
    37.             gen == UnityEngine.iOS.DeviceGeneration.iPadMini4Gen ||
    38.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch1Gen ||
    39.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch2Gen ||
    40.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch3Gen ||
    41.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch4Gen ||
    42.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch5Gen ||
    43.             gen == UnityEngine.iOS.DeviceGeneration.iPodTouch6Gen)
    44.         {
    45.             Debug.Log("Device not supported");
    46.             return false;
    47.         }
    48.  
    49.         return true;
    50.         #endif
    51.  
    52.         return false;
    53.     }
     
  14. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks! Good catch, it seemed to work on some devices... but not on others... so your version should be consistent.