Skip to content

Commit

Permalink
iOS: Use modern replacements for deprecated functions, when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jul 15, 2017
1 parent efe179c commit 01050d4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/video/SDL_sysvideo.h
Expand Up @@ -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_ */

Expand Down
12 changes: 6 additions & 6 deletions src/video/SDL_video.c
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
11 changes: 6 additions & 5 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -513,23 +513,24 @@ - (void)sendDropFileForURL:(NSURL *)url
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

Expand Down
5 changes: 2 additions & 3 deletions src/video/uikit/SDL_uikitmodes.m
Expand Up @@ -273,16 +273,15 @@ @implementation SDL_DisplayModeData
@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. */
if (SDL_GetDisplayBounds(displayIndex, rect) < 0) {
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];
}
Expand Down
19 changes: 18 additions & 1 deletion src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -114,7 +114,22 @@ - (void)setAnimationCallback:(int)interval
- (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];
}

Expand Down Expand Up @@ -155,10 +170,12 @@ - (NSUInteger)supportedInterfaceOrientations
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
{
Expand Down

0 comments on commit 01050d4

Please sign in to comment.