Search Unity

Access iPhone settings from Unity?

Discussion in 'iOS and tvOS' started by zigglr, Jun 2, 2016.

  1. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    Does anyone know how to access the iPhone settings from Unity in order to turn off / on the notifications setting for my app? Thanks
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You can use the following native iOS (Objective-C )code. Note that it only works with iOS 8 or higher:
    Code (CSharp):
    1. void OpenSettingsMenu() {
    2.     if (&UIApplicationOpenSettingsURLString != NULL) {
    3.         NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    4.         [[UIApplication sharedApplication] openURL:appSettings];
    5.     }
    6. }
    See this link for more details.
     
    andymads likes this.
  3. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    Thanks, so is there any code to turn off the notifications without the user having to do it manually through their settings page?
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I don't think you can do that.
     
  5. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    Ok. So this code gets entered in Unity or I have to put it somewhere in xCode?
     
  6. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Was wondering about this as I was in an app the other day and it took me directly to its specific settings so I could enable notifications. Thanks for the code snippet.
     
  7. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    Do you know where in xCode this code should be put? And how do I then call it in Unity? Thanks
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Read about native iOS plugins in the manual: http://docs.unity3d.com/Manual/PluginsForIOS.html

    In general this requires a few simple steps:
    1. Add the native code to your Unity project. Starting with Unity 5, you can drop these files (an .m file and a matching .h header) anywhere in the project. The plugin inspector allows you to select which platforms these files are relevant for (in this case - iOS).
    2. Define an "extern" method (with the DllImport attribute) like in the link above.
    3. Call this method, which will result in calling the native method.
    Hope this helps :)
     
  9. Nachman

    Nachman

    Joined:
    Oct 22, 2013
    Posts:
    26
    This is very helpful but I had been trying to find online the url string for the Ads tracking and app analytics page and I can't find it anywhere. Any Ideas in how to access those pages?
    Thanks in advance.