Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

iOS 11 how to avoid conflicts with system gestures at screen edges?

Discussion in 'iOS and tvOS' started by UDN_f2797471-3ee5-4459-87fe-e6f33e1d8670, Sep 15, 2017.

  1. UDN_f2797471-3ee5-4459-87fe-e6f33e1d8670

    UDN_f2797471-3ee5-4459-87fe-e6f33e1d8670

    Joined:
    Apr 21, 2016
    Posts:
    9
    Apple has changed the way they handle gestures at the screen edges in iOS 11. Hiding the status bar in iOS 11 no longer causes the system to guess that you want to defer the system gestures. To keep the same behavior we need to override preferredScreenEdgesDeferringSystemGestures in our view controller.
    source: https://useyourloaf.com/blog/avoiding-conflicts-with-system-gestures-at-screen-edges/

    I can solve this by modifying UnityViewControllerBaseiOS.mm in the generated xcode project.
    - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures{
    return UIRectEdgeAll;
    }

    I want to solve this "inside unity" so other team members also get the fix and when re-export xcode project. How to do this?
     
  2. UDN_f2797471-3ee5-4459-87fe-e6f33e1d8670

    UDN_f2797471-3ee5-4459-87fe-e6f33e1d8670

    Joined:
    Apr 21, 2016
    Posts:
    9
    solved it myself,

    put this file in /Assets/Editor/DeferringSystemGestures.cs

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.Callbacks;
    using System.Collections;
    #if UNITY_IOS
    using UnityEditor.iOS.Xcode;
    #endif
    using System.IO;

    // https://useyourloaf.com/blog/avoiding-conflicts-with-system-gestures-at-screen-edges/

    public class DeferringSystemGestures
    {
    #if UNITY_CLOUD_BUILD
    // This method is added in the Advanced Features Settings on UCB
    // PostBuildProcessor.OnPostprocessBuildiOS
    public static void OnPostprocessBuildiOS (string exportPath)
    {
    Debug.Log("[UCB] OnPostprocessBuildiOS");
    ProcessPostBuild(BuildTarget.iPhone,exportPath);
    }
    #endif

    [PostProcessBuild]
    public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
    {
    #if !UNITY_CLOUD_BUILD
    Debug.Log ("[iOS] OnPostprocessBuild");
    ProcessPostBuild (buildTarget, path);
    #endif
    }

    public static void ProcessPostBuild(BuildTarget buildTarget, string path)
    {
    #if UNITY_IOS

    if (buildTarget == BuildTarget.iOS) {

    Debug.Log ("[iOS] OnPostprocessBuild - DeferringSystemGestures");

    string filePath = path + "/Classes/UI/UnityViewControllerBaseiOS.h";
    string[] lines = System.IO.File.ReadAllLines(filePath);
    string allString = "";
    for(int i=0; i<lines.Length; i++) {
    if(i == 14){
    allString += "- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures;\n";
    }
    allString += lines+"\n";
    }
    System.IO.File.WriteAllText(filePath, allString);



    filePath = path + "/Classes/UI/UnityViewControllerBaseiOS.mm";
    lines = System.IO.File.ReadAllLines(filePath);
    allString = "";
    for(int i=0; i<lines.Length; i++) {
    if(i == 39){
    allString += "- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures{\n return UIRectEdgeAll;\n}\n\n";
    }
    allString += lines+"\n";
    }
    System.IO.File.WriteAllText(filePath, allString);
    }

    #endif
    }
    }
     
  3. Mischawake

    Mischawake

    Joined:
    Dec 13, 2012
    Posts:
    3
    The above code has some typos, the two lines with:

    allString += lines+"\n";

    should be:

    allString += lines+"\n";