5

For my iPhone app I want to implement the option to upload files to Soundcloud by making use of the CocoaSoundCloudAPI. In the instructions "How to use the SoundCloud API directly" it is explained how to modally present a loginViewController:

- (void)login {

  [SCSoundCloud requestAccessWithPreparedAuthorizationURLHandler:
     ^(NSURL *preparedURL){

  SCLoginViewController *loginViewController;
  loginViewController = 
    [SCLoginViewController loginViewControllerWithPreparedURL:preparedURL
                                            completionHandler:^(NSError *error){

       if (SC_CANCELED(error)) {
           NSLog(@"Canceled!");
       } else if (error) {
           NSLog(@"Ooops, something went wrong: %@", [error localizedDescription]);
       } else {
           NSLog(@"Done!");
       }

     }];

     [self presentModalViewController:loginViewController
                             animated:YES];

  }];
}

Now I replaced

     [self presentModalViewController:loginViewController
                             animated:YES];

with

     [self presentViewController:loginViewController
                        animated:YES
                      completion:nil];

because the first method is deprecated in iOS 7.

But the problem is that the Soundcloud loginViewController overlaps the status bar when presented in this fashion. And since I don't want to change the Soundcloud API I do not have the option to customize the loginViewController accordingly e.g. in its - viewDidLoad method (as suggested in many other posts on Stackoverflow).

enter image description here

Unfortunately there is a toolbar with a button on top the loginViewController. How can I configure my loginViewController from inside my own (presenting) view controller so that it won't overlap with the status bar when presented?

2
  • Have you been able to figure this out yet? I'm havingn the same issue.
    – Jawap
    Mar 2, 2014 at 18:37
  • @Jawap: Unfortunately I haven't found a real solution for this problem but I came up with a workaround that does the job. Will post the answer in a moment.
    – Mischa
    Mar 2, 2014 at 19:44

1 Answer 1

7

As mentioned in my comment to the original question I did not find a neat solution for this problem. However I managed to implement a workaround that does the job:

The basic idea is to add the SCLoginViewController as a child view controller of another custom view controller that is not part of the Soundcloud framework and that you can customize to your needs. This is my new login method that presents the login view controller:

- (BOOL)loginToSoundcloud {

    BOOL __block success = NO;
    [SCSoundCloud requestAccessWithPreparedAuthorizationURLHandler:^(NSURL *preparedURL){

        SCLoginViewController *loginViewController;
        loginViewController = 
        [SCLoginViewController loginViewControllerWithPreparedURL:preparedURL
                                                completionHandler:^(NSError *error){

             if (SC_CANCELED(error)) {
                 NSLog(@"Canceled!");
             } else if (error) {
                 NSLog(@"Ooops, something went wrong: %@", [error localizedDescription]);
             } else {
                 NSLog(@"Done!");
                 success = YES;
             }

        }];                                          

        /* BEGIN workaround for iOS7 bug:
           when modally presenting a view controller it overlaps the status bar */

        CBContainerVCToFixStatusBarOverlap *containerVC = [[CBContainerVCToFixStatusBarOverlap alloc] init];
        [containerVC addChildViewController:loginViewController];
        containerVC.view.backgroundColor = [UIColor clearColor];

        if ([CBAppDelegate iOSVersionIs7OrHigher]) {
            loginViewController.view.frame = 
                     CGRectMake(loginViewController.view.frame.origin.x,
                                loginViewController.view.frame.origin.y + 20,
                                containerVC.view.frame.size.width,
                                containerVC.view.frame.size.height - 20);
        } else {
            loginViewController.view.frame = 
                     CGRectMake(loginViewController.view.frame.origin.x,
                                loginViewController.view.frame.origin.y,
                                containerVC.view.frame.size.width,
                                containerVC.view.frame.size.height);
        }
        [containerVC.view addSubview:loginViewController.view];

        /* END workaround for iOS7 bug */

        [self presentViewController:containerVC 
                           animated:YES 
                         completion:nil];

    }];

    return success;
}

To check for the iOS version I implemented the following method in my CBAppDelegate:

+ (BOOL)iOSVersionIs7OrHigher {
    return floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1;
}

CBContainerVCToFixStatusBarOverlap is a simple view controller class with no additional methods and only one declared property. This is the content of CBContainerVCToFixStatusBarOverlap.h:

@interface CBContainerVCToFixStatusBarOverlap : UIViewController
@property (strong, nonatomic) IBOutlet UIView *containerView;
@end
2
  • 1
    This works well, thanks! As a note though, you don't need a custom subclassed view controller, you can just create an instance of UIViewController for the container and do the same thing.
    – beebcon
    Sep 16, 2014 at 1:56
  • @Mischa, thank you it is worked for me. The only thing I changed was backgroundColor, because when I used clearColor, status bar became black, so I changed it to whiteColor.
    – akmal
    Jan 30, 2015 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.