iOS: Use modern replacements for deprecated functions, when available.
authorAlex Szpakowski <slime73@gmail.com>
Sat, 15 Jul 2017 17:41:58 -0300
changeset 111475b2841f73a33
parent 11146 42fd7dcd5f7e
child 11148 9bdb766ec7e5
iOS: Use modern replacements for deprecated functions, when available.
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitmodes.m
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/SDL_sysvideo.h	Fri Jul 14 17:42:11 2017 -0300
     1.2 +++ b/src/video/SDL_sysvideo.h	Sat Jul 15 17:41:58 2017 -0300
     1.3 @@ -419,12 +419,12 @@
     1.4  
     1.5  extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
     1.6  
     1.7 -extern void SDL_OnApplicationWillTerminate();
     1.8 -extern void SDL_OnApplicationDidReceiveMemoryWarning();
     1.9 -extern void SDL_OnApplicationWillResignActive();
    1.10 -extern void SDL_OnApplicationDidEnterBackground();
    1.11 -extern void SDL_OnApplicationWillEnterForeground();
    1.12 -extern void SDL_OnApplicationDidBecomeActive();
    1.13 +extern void SDL_OnApplicationWillTerminate(void);
    1.14 +extern void SDL_OnApplicationDidReceiveMemoryWarning(void);
    1.15 +extern void SDL_OnApplicationWillResignActive(void);
    1.16 +extern void SDL_OnApplicationDidEnterBackground(void);
    1.17 +extern void SDL_OnApplicationWillEnterForeground(void);
    1.18 +extern void SDL_OnApplicationDidBecomeActive(void);
    1.19  
    1.20  #endif /* SDL_sysvideo_h_ */
    1.21  
     2.1 --- a/src/video/SDL_video.c	Fri Jul 14 17:42:11 2017 -0300
     2.2 +++ b/src/video/SDL_video.c	Sat Jul 15 17:41:58 2017 -0300
     2.3 @@ -3863,17 +3863,17 @@
     2.4  /*
     2.5   * Functions used by iOS application delegates
     2.6   */
     2.7 -void SDL_OnApplicationWillTerminate()
     2.8 +void SDL_OnApplicationWillTerminate(void)
     2.9  {
    2.10      SDL_SendAppEvent(SDL_APP_TERMINATING);
    2.11  }
    2.12  
    2.13 -void SDL_OnApplicationDidReceiveMemoryWarning()
    2.14 +void SDL_OnApplicationDidReceiveMemoryWarning(void)
    2.15  {
    2.16      SDL_SendAppEvent(SDL_APP_LOWMEMORY);
    2.17  }
    2.18  
    2.19 -void SDL_OnApplicationWillResignActive()
    2.20 +void SDL_OnApplicationWillResignActive(void)
    2.21  {
    2.22      if (_this) {
    2.23          SDL_Window *window;
    2.24 @@ -3885,17 +3885,17 @@
    2.25      SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
    2.26  }
    2.27  
    2.28 -void SDL_OnApplicationDidEnterBackground()
    2.29 +void SDL_OnApplicationDidEnterBackground(void)
    2.30  {
    2.31      SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    2.32  }
    2.33  
    2.34 -void SDL_OnApplicationWillEnterForeground()
    2.35 +void SDL_OnApplicationWillEnterForeground(void)
    2.36  {
    2.37      SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
    2.38  }
    2.39  
    2.40 -void SDL_OnApplicationDidBecomeActive()
    2.41 +void SDL_OnApplicationDidBecomeActive(void)
    2.42  {
    2.43      SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
    2.44  
     3.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Fri Jul 14 17:42:11 2017 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sat Jul 15 17:41:58 2017 -0300
     3.3 @@ -513,23 +513,24 @@
     3.4      SDL_SendDropComplete(NULL);
     3.5  }
     3.6  
     3.7 -#if TARGET_OS_TV
     3.8 -/* TODO: Use this on iOS 9+ as well? */
     3.9 +#if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0)
    3.10 +
    3.11  - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
    3.12  {
    3.13      /* TODO: Handle options */
    3.14      [self sendDropFileForURL:url];
    3.15      return YES;
    3.16  }
    3.17 -#endif /* TARGET_OS_TV */
    3.18  
    3.19 -#if !TARGET_OS_TV
    3.20 +#else
    3.21 +
    3.22  - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    3.23  {
    3.24      [self sendDropFileForURL:url];
    3.25      return YES;
    3.26  }
    3.27 -#endif /* !TARGET_OS_TV */
    3.28 +
    3.29 +#endif
    3.30  
    3.31  @end
    3.32  
     4.1 --- a/src/video/uikit/SDL_uikitmodes.m	Fri Jul 14 17:42:11 2017 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Sat Jul 15 17:41:58 2017 -0300
     4.3 @@ -273,6 +273,7 @@
     4.4      @autoreleasepool {
     4.5          int displayIndex = (int) (display - _this->displays);
     4.6          SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
     4.7 +        CGRect frame = data.uiscreen.bounds;
     4.8  
     4.9          /* the default function iterates displays to make a fake offset,
    4.10           as if all the displays were side-by-side, which is fine for iOS. */
    4.11 @@ -280,9 +281,7 @@
    4.12              return -1;
    4.13          }
    4.14  
    4.15 -        CGRect frame = data.uiscreen.bounds;
    4.16 -
    4.17 -#if !TARGET_OS_TV
    4.18 +#if !TARGET_OS_TV && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
    4.19          if (!UIKit_IsSystemVersionAtLeast(7.0)) {
    4.20              frame = [data.uiscreen applicationFrame];
    4.21          }
     5.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Fri Jul 14 17:42:11 2017 -0300
     5.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Sat Jul 15 17:41:58 2017 -0300
     5.3 @@ -114,7 +114,22 @@
     5.4  - (void)startAnimation
     5.5  {
     5.6      displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
     5.7 -    [displayLink setFrameInterval:animationInterval];
     5.8 +
     5.9 +#ifdef __IPHONE_10_3
    5.10 +    SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
    5.11 +
    5.12 +    if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
    5.13 +        && data != nil && data.uiwindow != nil
    5.14 +        && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
    5.15 +        displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
    5.16 +    } else
    5.17 +#endif
    5.18 +    {
    5.19 +#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
    5.20 +        [displayLink setFrameInterval:animationInterval];
    5.21 +#endif
    5.22 +    }
    5.23 +
    5.24      [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    5.25  }
    5.26  
    5.27 @@ -155,10 +170,12 @@
    5.28      return UIKit_GetSupportedOrientations(window);
    5.29  }
    5.30  
    5.31 +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
    5.32  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
    5.33  {
    5.34      return ([self supportedInterfaceOrientations] & (1 << orient)) != 0;
    5.35  }
    5.36 +#endif
    5.37  
    5.38  - (BOOL)prefersStatusBarHidden
    5.39  {