Facebook 앱에서와 같이 프로그래밍 방식으로 설정을 여는 방법은 무엇입니까?
내 앱에서 프로그래밍 방식으로 설정을 열어야합니다. 나는 SO를 검색했지만 사람들이 불가능하다고 말하는 모든 곳에서. 하지만 오늘은 페이스 북 앱에서 구현 된 것을 보았습니다. 에 버튼이 있으며 UIAlertView
클릭하면 설정이 열립니다. 그래서 실제로 이것은 설정을 열 수 있으며, 이것을 직접 목격했습니다. 하지만 어떻게할까요? 페이스 북이 어떻게 그렇게하는지 아는 사람 있나요?
그렇게 할 수있는 API 호출이 없습니다.
시스템 대화 상자, Apple Frameworks의 대화 상자 만 설정 앱을 열 수 있습니다. iOS 5에는 시스템 대화 상자를 여는 앱 URL 체계가 있었지만 Apple은 나중에 제거했습니다.
iOS 8이 출시되면서 앱 페이지에서 설정 대화 상자를 열 수 있습니다.
if (&UIApplicationOpenSettingsURLString != NULL) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
else {
// Present some dialog telling the user to open the settings app.
}
iOS 8에서는 프로그래밍 방식으로 설정을 열 수 있습니다!
다음은 코드입니다.
- (void)openSettings
{
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
앱에 자체 설정 번들이있는 경우 앱 설정이 표시된 설정이 열립니다. 앱에 설정 번들이없는 경우 기본 설정 페이지가 표시됩니다.
iOS 8에서는 프로그래밍 방식으로 설정을 열 수 있습니다!
다음은 설정 앱에서 현재 알려진 URL 목록입니다.
- (void) openSettings
{
if (&UIApplicationOpenSettingsURLString != nil)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
else
NSLog(@"UIApplicationOpenSettingsURLString is not available in current iOS version");
}
- prefs : root = General & path = 정보
- prefs : root = General & path = ACCESSIBILITY
- prefs : root = AIRPLANE_MODE
- prefs : root = General & path = AUTOLOCK
- prefs : root = General & path = USAGE / CELLULAR_USAGE
- prefs : root = 밝기
- prefs : root = General & path = Bluetooth
- prefs : root = General & path = DATE_AND_TIME
- prefs : root = FACETIME
- prefs : root = 일반
- prefs : root = General & path = Keyboard
- prefs : root = CASTLE
- prefs : root = CASTLE & path = STORAGE_AND_BACKUP
- prefs : root = General & path = INTERNATIONAL
- prefs : root = LOCATION_SERVICES
- prefs : root = ACCOUNT_SETTINGS
- prefs : root = MUSIC
- prefs : root = MUSIC & path = EQ
- prefs : root = MUSIC & path = VolumeLimit
- prefs : root = General & path = Network
- prefs : root = NIKE_PLUS_IPOD
- prefs : root = 참고
- prefs : root = NOTIFICATIONS_ID
- prefs : root = 전화
- prefs : root = 사진
- prefs : root = General & path = ManagedConfigurationList
- prefs : root = General & path = 재설정
- prefs : root = 사운드 & path = 벨소리
- prefs : root = Safari
- prefs : root = General & path = Assistant
- prefs : root = 사운드
- prefs : root = General & path = SOFTWARE_UPDATE_LINK
- prefs : root = STORE
- prefs : root = TWITTER
- prefs : root = General & path = USAGE
- prefs : root = VIDEO
- prefs : root = General & path = Network / VPN
- prefs : root = 배경 화면
- prefs : root = WIFI
- prefs : root = INTERNET_TETHERING
Swift에서 Vito Ziv의 답변.
func openSettings() {
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!, completionHandler: nil)
}
이 질문이 참조하는 Facebook 앱의 경고는 Info.plist 파일에서 UIRequiresPersistentWiFi 를 YES로 설정 하고 사용자가 네트워크 연결없이 앱을 시작할 때 iOS가 자체적으로 표시 하는 표준 경고입니다 .
여기에 토론을 요약하면 다음과 같습니다.
- 설정 앱 의 루트 수준 으로 이동하는 데 사용할 수있는 URL이 없습니다 .
- iOS 8에서 UIApplicationOpenSettingsURLString 을 사용하여 사용자를 설정 앱의 앱 섹션 으로 보낼 수 있습니다 .
- 앱은 UIRequiresPersistentWiFi를 YES로 설정하여 설정 앱의 루트 수준을 여는 Facebook과 동일한 경고를 표시 할 수 있습니다 .
prefs:root=
및에 대한 메모 Prefs:root
입니다.
예, 우리 앱은 오늘 및 URL 체계 로 인해 Apple 에서 거부했습니다 . 그들은 개인 API입니다.prefs:root=
App-Prefs:root
(2018-06-29)
Swift 4의 경우
UIApplication.openSettingsURLString 만 설정을 여는 공용 API입니다.
if (&UIApplicationOpenSettingsURLString != NULL)
iOS 8 이상에서는 항상 TRUE입니다. 이렇게 편집 할 수 있습니다.
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
(iOS 10 용 새로운 openURL 포함)
응용 프로그램 설정을 열려면 UIApplicationOpenSettingsURLString을 사용하는 쓰기 메서드가 필요합니다.
fileprivate func openSettings() {
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
}
필요한 경우 여러 설정 중 하나를 열려면이 기능을 사용해야합니다.
fileprivate func openSettings() {
UIApplication.shared.open(URL(string:"App-Prefs:root=General")!)
}
에서 자체 응용 프로그램의 설정을 열려면 iOS 8 and later
다음 코드를 사용하십시오.
- (void) openSettings
{
if(&UIApplicationOpenSettingsURLString != nil)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
else
NSLog(@"UIApplicationOpenSettingsURLString is not available in current iOS version");
}
참조 및 자세한 설명을 위해 따르십시오
if (&UIApplicationOpenSettingsURLString != NULL) {
UIAlertView_Blocks *alertView = [[UIAlertView_Blocks alloc] initWithTitle:NSLocalizedString(@"Camera Access Denied", nil)
message:NSLocalizedString(@"You must allow camera access in Settings", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"Open Settings", nil), nil];
[alertView showWithDissmissBlock:^(NSInteger buttonIndex) {
if (alertView.cancelButtonIndex != buttonIndex) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}];
}
else {
UIAlertView_Blocks *alertView = [[UIAlertView_Blocks alloc] initWithTitle:NSLocalizedString(@"Camera Access Denied", nil)
message:NSLocalizedString(@"You must allow camera access in Settings > Privacy > Camera", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil, nil];
[alertView showWithDissmissBlock:^(NSInteger buttonIndex) {
}];
}
다음은 UIAlertController 및 UIAlertAction이있는 Swift 3 예제입니다.
func showSettingsPopup() {
let alertVC = UIAlertController(title: "Notifications disabled", message: "Please, turn on notifications if you want to receive a reminder messages.", preferredStyle: .alert)
let close = UIAlertAction(title: "Close", style: .destructive, handler: { (action) in
print("close action handler")
})
let openSettings = UIAlertAction(title: "Open settings", style: .default, handler: { (action) in
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
print("Settings are opened: \(success)")
})
}
})
alertVC.addAction(openSettings)
alertVC.addAction(close)
present(alertVC, animated: true, completion: nil)
}
if #available(iOS 10.0, *) {
if let url = URL(string: "App-Prefs:root=Privacy") {
UIApplication.shared.open(url, completionHandler: .none)
}
} else {
// Fallback on earlier versions
}
앱에서 개인 정보 설정 열기
를 사용하는 대신 prefs:
사용하십시오.App-Prefs:
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @"App-Prefs:root=WIFI"]]) {
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"App-Prefs:root=WIFI"]];
}
.
모든 것이 여기에 있습니다 : https://medium.com/@thanhvtrn/how-to-open-settings-wifi-in-swift-on-ios-10-1d94cf2c2e60
여기에 제공된 많은 답변에서 "App-Prefs : root" "prefs : root"를 사용하는 것을 볼 수 있습니다. 앱에서 설정 앱을 열 때 사용해서는 안됩니다. Apple에 따르면 이것은 비공개 URL 체계이며 사용하면 앱이 거부됩니다.
SWIFT 3
UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
'Development Tip' 카테고리의 다른 글
암시 적으로 'Int'형식을 'T'로 변환 할 수 없습니다. (0) | 2020.10.17 |
---|---|
socket.io 클라이언트 라이브러리는 어디에 있습니까? (0) | 2020.10.17 |
iPhone xib를 iPad xib로 변환 하시겠습니까? (0) | 2020.10.17 |
새로 추가 된 dom 요소에 바인딩되지 않는 jQuery 함수 (0) | 2020.10.17 |
파생 클래스가 수퍼 메서드를 호출하도록 강제하는 방법은 무엇입니까? (0) | 2020.10.17 |