Commit 01050d4ed11389a0b92ba53da5501da014298f89

Alex Szpakowski 2017-07-15T17:41:58

iOS: Use modern replacements for deprecated functions, when available.

diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 94ba285..d1f5658 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -419,12 +419,12 @@ extern SDL_bool SDL_ShouldAllowTopmost(void);
 
 extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
 
-extern void SDL_OnApplicationWillTerminate();
-extern void SDL_OnApplicationDidReceiveMemoryWarning();
-extern void SDL_OnApplicationWillResignActive();
-extern void SDL_OnApplicationDidEnterBackground();
-extern void SDL_OnApplicationWillEnterForeground();
-extern void SDL_OnApplicationDidBecomeActive();
+extern void SDL_OnApplicationWillTerminate(void);
+extern void SDL_OnApplicationDidReceiveMemoryWarning(void);
+extern void SDL_OnApplicationWillResignActive(void);
+extern void SDL_OnApplicationDidEnterBackground(void);
+extern void SDL_OnApplicationWillEnterForeground(void);
+extern void SDL_OnApplicationDidBecomeActive(void);
 
 #endif /* SDL_sysvideo_h_ */
 
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 7b1bffd..ab3a8ef 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3863,17 +3863,17 @@ SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
 /*
  * Functions used by iOS application delegates
  */
-void SDL_OnApplicationWillTerminate()
+void SDL_OnApplicationWillTerminate(void)
 {
     SDL_SendAppEvent(SDL_APP_TERMINATING);
 }
 
-void SDL_OnApplicationDidReceiveMemoryWarning()
+void SDL_OnApplicationDidReceiveMemoryWarning(void)
 {
     SDL_SendAppEvent(SDL_APP_LOWMEMORY);
 }
 
-void SDL_OnApplicationWillResignActive()
+void SDL_OnApplicationWillResignActive(void)
 {
     if (_this) {
         SDL_Window *window;
@@ -3885,17 +3885,17 @@ void SDL_OnApplicationWillResignActive()
     SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
 }
 
-void SDL_OnApplicationDidEnterBackground()
+void SDL_OnApplicationDidEnterBackground(void)
 {
     SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
 }
 
-void SDL_OnApplicationWillEnterForeground()
+void SDL_OnApplicationWillEnterForeground(void)
 {
     SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
 }
 
-void SDL_OnApplicationDidBecomeActive()
+void SDL_OnApplicationDidBecomeActive(void)
 {
     SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
 
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index 17dc4d9..b2badaa 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -513,23 +513,24 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
     SDL_SendDropComplete(NULL);
 }
 
-#if TARGET_OS_TV
-/* TODO: Use this on iOS 9+ as well? */
+#if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0)
+
 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
 {
     /* TODO: Handle options */
     [self sendDropFileForURL:url];
     return YES;
 }
-#endif /* TARGET_OS_TV */
 
-#if !TARGET_OS_TV
+#else
+
 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
 {
     [self sendDropFileForURL:url];
     return YES;
 }
-#endif /* !TARGET_OS_TV */
+
+#endif
 
 @end
 
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index 12a4083..0798166 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -273,6 +273,7 @@ UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
     @autoreleasepool {
         int displayIndex = (int) (display - _this->displays);
         SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
+        CGRect frame = data.uiscreen.bounds;
 
         /* the default function iterates displays to make a fake offset,
          as if all the displays were side-by-side, which is fine for iOS. */
@@ -280,9 +281,7 @@ UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
             return -1;
         }
 
-        CGRect frame = data.uiscreen.bounds;
-
-#if !TARGET_OS_TV
+#if !TARGET_OS_TV && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
         if (!UIKit_IsSystemVersionAtLeast(7.0)) {
             frame = [data.uiscreen applicationFrame];
         }
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index a8e36ef..a4be1ed 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -114,7 +114,22 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
 - (void)startAnimation
 {
     displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
-    [displayLink setFrameInterval:animationInterval];
+
+#ifdef __IPHONE_10_3
+    SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+
+    if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
+        && data != nil && data.uiwindow != nil
+        && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
+        displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
+    } else
+#endif
+    {
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
+        [displayLink setFrameInterval:animationInterval];
+#endif
+    }
+
     [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
 }
 
@@ -155,10 +170,12 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
     return UIKit_GetSupportedOrientations(window);
 }
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
 {
     return ([self supportedInterfaceOrientations] & (1 << orient)) != 0;
 }
+#endif
 
 - (BOOL)prefersStatusBarHidden
 {