13

I know I can open the settings app in iOS 5 using

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

but is there a way to open the Twitter settings page directly? The desired functionality can be seen when you try to present a TWTweetComposeViewController and you have not set up a Twitter account.

Andrew
  • 567
  • 2
  • 5
  • 18
  • A very extensive list: http://iphoneza.co.za/IconSettings/ – Sahil Nov 15 '11 at 02:11
  • https://github.com/Burnsoft/Settings-Swipe I recently open sourced the original version of my latest app, as the features will likely never make it on the appstore. It uses local notifications to allow easy access to your iOS5 settings. Including Twitter. – Nik Burns Dec 08 '11 at 15:53
  • I recently came up with a way to send a user to Twitter Settings that works in iOS 5.1+ http://goto11.net/programmatically-open-twitter-settings-on-ios-5-1/ – nrj Aug 21 '12 at 19:33
  • To get this to work in iOS 6, check out the answer I posted here: http://stackoverflow.com/questions/11325266/open-twitter-setting-from-acaccountstore-ios-5-1-twitter/13293846#13293846 – Senior Nov 08 '12 at 16:59
  • Using Twitter Framework it may helps you : http://stackoverflow.com/questions/13946062/twitter-framework-for-ios6-how-to-login-through-settings-from-app – RayofHope Feb 13 '13 at 11:11

6 Answers6

30

Try,

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];    
Jorge Moreno
  • 323
  • 4
  • 5
  • Awesome. I was really hoping "prefs:root=LocationServices" would work... but alas :( – Sahil Nov 04 '11 at 22:37
  • Any idea on getting this to work for third party app settings? I tried using my app's bundle display name and it didn't work. EDIT: it works! It is case sensitive. – Héctor Ramos Nov 04 '11 at 22:53
  • 1
    has anyone had experience of recent app rejections for using the twitter pref url? as these are private api calls, I expect that even though directing a user to add a twitter account would still get rejected? (although any common sense person could see that directing user to settings is the right thing to do) – Nik Burns Dec 08 '11 at 15:55
  • @Nik I have this in production apps, none were rejected – james_womack Feb 24 '12 at 03:57
  • interesting. I've had clear indication from app review that any use of prefs URL scheme will be rejected. Have you tried to an update recently? cheers Nik – Nik Burns Feb 24 '12 at 15:36
  • 1
    @cirrostratus is 5.1 breaking prefs causing your users problems? – Nik Burns Mar 14 '12 at 14:19
4

I found out that the root value is the key of the localized string found in the "Settings.strings" file of the Preferences.app. Here are some values that I tested to work:

General: General
iCloud: CASTLE
Mail: ACCOUNT_SETTINGS
Twitter: TWITTER
Safari: Safari
Music: MUSIC
Video: VIDEO
Photos: Photos
Notes: NOTES
Store: STORE

However I can't figure out how to do this with my own app's settings.
prefs:root=Apps&path=<CFBundleDisplayName> seems not to work.

Martin Hering
  • 429
  • 3
  • 11
3

@Sahil

Use

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

to open straight to Location Services

user814712
  • 281
  • 2
  • 6
2

The awesome answers are already given but here is the complete snippet to open twitter settings in Settings using UIAlertController and Swift 3 :

 let alert = UIAlertController(title: "No Twitter Accounts", message: "There are no Twitter accounts configured. You can add or create a Twitter account in Settings.", preferredStyle: .alert)
        let firstAction = UIAlertAction(title: "Cancel", style: .default, handler: {(action: UIAlertAction) -> Void in

        })
        let secondAction = UIAlertAction(title: "Settings", style: .default, handler: {(action: UIAlertAction) -> Void in

            let url = URL(string:"App-Prefs:root=TWITTER")!
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            } else {
                UIApplication.shared.openURL(url)
            }
        })
        alert.addAction(firstAction)
        alert.addAction(secondAction)
        self.present(alert, animated: true, completion: nil)
Anurag Sharma
  • 4,276
  • 2
  • 28
  • 44
1

Just show the composer. If no Twitter Account is available, it will show an AlertView to go to Settings

var controller = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
controller.setInitialText("My Post")
self.presentViewController(controller, animated: true, completion: nil)
Kaptain
  • 1,358
  • 12
  • 20
0

Using the prefs:root scheme is not recommended. It will very likely be a breaking change with iOS update on the device and could lead to your app being rejected from the app store.

https://gist.github.com/phynet/471089a51b8f940f0fb4

Bueno
  • 1,840
  • 2
  • 15
  • 17