Fixes the bug that MFMailComposeViewController not presented properly.
The get_viewcontroller() function assumed the SDL window is always the first window in the shared application. However, it is not there. This commit assumes the SDL window is the keyWindow of the shared application. In the mailComposeController:didFinishWithResult:error: method. The code originally uses the same get_viewcontroller() function to dismiss the modal view. However, uses [controller presentingViewController] is more promising to make sure the view controller that presents the MFMailComposeViewController. There are also errors showed in the log if animation is disabled. So I changed to use animation on both presenting and dismissing. And the errors in log gone. Signed-off-by: Olli Wang <olliwang@ollix.com>
This commit is contained in:
parent
cdd79ab77c
commit
a5015a746b
1 changed files with 10 additions and 11 deletions
|
@ -13,13 +13,13 @@
|
||||||
/* guess the view controller from our SDL window.
|
/* guess the view controller from our SDL window.
|
||||||
*/
|
*/
|
||||||
UIViewController *get_viewcontroller(void) {
|
UIViewController *get_viewcontroller(void) {
|
||||||
NSArray *windows = [[UIApplication sharedApplication] windows];
|
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
|
||||||
if ( windows == NULL ) {
|
if ( window == NULL ) {
|
||||||
printf("ios_wrapper: unable to get windows from shared application\n");
|
printf("ios_wrapper: unable to get key window from shared application\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
UIWindow *uiWindow = [windows objectAtIndex:0];
|
// return window.rootViewController;
|
||||||
UIView* view = [uiWindow.subviews objectAtIndex:0];
|
UIView* view = [window.subviews objectAtIndex:0];
|
||||||
id nextResponder = [view nextResponder];
|
id nextResponder = [view nextResponder];
|
||||||
if( [nextResponder isKindOfClass:[UIViewController class]] )
|
if( [nextResponder isKindOfClass:[UIViewController class]] )
|
||||||
return (UIViewController *)nextResponder;
|
return (UIViewController *)nextResponder;
|
||||||
|
@ -42,7 +42,6 @@ UIViewController *get_viewcontroller(void) {
|
||||||
@synthesize callback;
|
@synthesize callback;
|
||||||
|
|
||||||
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
|
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
|
||||||
UIViewController* viewController = get_viewcontroller();
|
|
||||||
static char *statuses[] = {"unknown", "cancelled", "saved", "sent", "failed"};
|
static char *statuses[] = {"unknown", "cancelled", "saved", "sent", "failed"};
|
||||||
|
|
||||||
if ( callback != NULL ) {
|
if ( callback != NULL ) {
|
||||||
|
@ -58,8 +57,8 @@ UIViewController *get_viewcontroller(void) {
|
||||||
callback(status, userdata);
|
callback(status, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
[viewController becomeFirstResponder];
|
UIViewController* viewController = [controller presentingViewController];
|
||||||
[viewController dismissModalViewControllerAnimated:NO];
|
[viewController dismissModalViewControllerAnimated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -103,7 +102,7 @@ int ios_send_email(char *subject, char *text, char *mimetype, char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.modalPresentationStyle = UIModalPresentationPageSheet;
|
controller.modalPresentationStyle = UIModalPresentationPageSheet;
|
||||||
[viewController presentModalViewController:controller animated:NO];
|
[viewController presentModalViewController:controller animated:YES];
|
||||||
[controller release];
|
[controller release];
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue