35

Looks like iOS 5.1 has broken the standard URL encoding for navigating a user to a Preference.

For example:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];

Works in iOS 5.0 but not in iOS 5.1 (both device and simulator).

Has anyone found a way to replicate this functionality in iOS 5.1?

Natan R.
  • 5,141
  • 1
  • 31
  • 48
James Jones
  • 1,486
  • 1
  • 12
  • 22
  • Wow, Apple was quick to remove that one... Have you tried getting the Info.plist of the Settings app and checking if there are any registered URL schemes? – fbernardo Mar 09 '12 at 01:03
  • 1
    I popped open the Preferences.plist. Looks like they removed the value for the kPreferencePositionKey (which used to be prefs:...). I see several new keys (WebDatabaseDirectory, WebKitLocalStoreDatabasePathPreferenceKey, AutomaticMinimizationEnabled, and UserDictionarySampleShortcutsAdded). Some of those sound interesting, now the fun part is where to start. – James Jones Mar 09 '12 at 01:16
  • AutomaticMinimization sounds fun indeed... – fbernardo Mar 09 '12 at 01:22
  • stop posting bad urls – Swati Apr 25 '13 at 11:02

4 Answers4

13

It is little tricky , i get by the removing the subviews in *TWTWeetComposeViewController*, so it shows only alert when user is not loged in and by the clicking on setting button , we can open Setting page in my app.

     + (void)setAlertForSettingPage :(id)delegate 
    {
     // Set up the built-in twitter composition view controller.
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];


        // Create the completion handler block.
        [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [delegate dismissModalViewControllerAnimated:YES];
        }];

        // Present the tweet composition view controller modally.
        [delegate presentModalViewController:tweetViewController animated:YES];
        //tweetViewController.view.hidden = YES;
        for (UIView *view in tweetViewController.view.subviews){
            [view removeFromSuperview];
        }

     } 

here , delegate is your viewcontroller , if you are using this method inside your viewcontroller just use self instead of delegate.

EDIT: If you get any deprecated errors, use the following iOS6 compatible code instead:

- (void)setAlertForSettingPage
{
    // Set up the built-in twitter composition view controller.
    SLComposeViewController *tweetViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    // Present the tweet composition view controller modally.
    [self presentViewController:tweetViewController animated:YES completion:nil];
    for (UIView *view in tweetViewController.view.subviews){
        [view removeFromSuperview];
    }
}
marmor
  • 27,641
  • 11
  • 107
  • 150
PJR
  • 13,052
  • 13
  • 64
  • 104
  • This is the only working solution I've found! Thank you! – Eduardo Cobuci Sep 15 '14 at 22:41
  • @EduardoCobuci were you able to remove the tweet box in the background? I see the settings / cancel alert but there is a Tweet Box at the back, how do we remove that? – Jatin Oct 06 '14 at 17:44
11

No I don’t know a way to replicate this functionality.

But what you can do is file a Radar requesting the restoration. Here is a radar requesting that the schemes be documented in the first place.

David Barnard has confirmed that iOS 5.1 breaks the settings apps URL schemes.


Update: iOS 8 has similar functionality for opening your app’s settings. Thanks Apple, Mike and Soto_iGhost.

The constant UIApplicationOpenSettingsURLString (UIApplication Documentation) will open the settings for your app and not, say Twitter’s settings. Not exactly the same functionality but much cleaner than before and now officially recognized.

This should be extra useful now that each app has a place in Settings for using privacy, cellular data, background app refresh and notifications.

Community
  • 1
  • 1
fearmint
  • 5,276
  • 2
  • 33
  • 45
  • Thanks for the reply. This is a big bummer, not sure why Apple felt the need to remove this functionality. – James Jones Mar 13 '12 at 15:49
  • 1
    These are indeed not good news. We used this as well for a client within an enterprise app. – axooh Mar 21 '12 at 14:06
  • It seems to still work if the button is in an alert, but not a regular button on UI – zambono Apr 27 '12 at 13:05
  • @zambono that would be great, can you provide us with a code sample showing this works? – fearmint Apr 27 '12 at 16:07
  • 1
    I just noticed it in my own app which was released by apple, if I have a regular button or an action in a tableview to go to settings it doesn't do anything, but a button in a UIAlertView does work. – zambono May 03 '12 at 13:11
  • 2
    @zambono could you provide a code example? I could not get it to work with UIAlertView. – lari May 08 '12 at 05:51
  • 1
    @JoePasq It seems we can open the settings from within the app again in iOS8. http://stackoverflow.com/a/25558855/2376248 Can you edit the answer? – Soto_iGhost Nov 17 '14 at 00:07
3

you can do this.

TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
                    if ([ctrl respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
                        // Manually invoke the alert view button handler
                        [(id <UIAlertViewDelegate>)ctrl alertView:nil
                                             clickedButtonAtIndex:0];
                    }
Saad
  • 8,857
  • 2
  • 41
  • 51
  • Nice work :) but its not returing back to app after loging-in the twitter account also the alert is still there :( – Zubair Feb 15 '13 at 12:05
  • plz view the link http://facebook.stackoverflow.com/questions/14950678/calling-uialertview-clickedbutton-at-index-programatically – Zubair Feb 21 '13 at 07:41
1

If you look in Twitter's framework (that Twitter view controller), it has "prefs:root=TWITTER" inside, 5.1 also has this line. So probably Apple made something to disable it for other apps, like some special key in plist or method "openURL" somehow checks if it's not a system app.

artysx
  • 533
  • 5
  • 14