Open Twitter settings in Settings app

2019-02-02 01:45发布

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.

6条回答
何必那么认真
2楼-- · 2019-02-02 02:17

Try,

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];    
查看更多
相关推荐>>
3楼-- · 2019-02-02 02:24

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

查看更多
▲ chillily
4楼-- · 2019-02-02 02:32

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)
查看更多
你好瞎i
5楼-- · 2019-02-02 02:34

@Sahil

Use

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

to open straight to Location Services

查看更多
姐就是有狂的资本
6楼-- · 2019-02-02 02:37

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.

查看更多
Explosion°爆炸
7楼-- · 2019-02-02 02:38

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)
查看更多
登录 后发表回答