2009-07-07 28 views
22

Tôi biết một ứng dụng có thể khởi chạy các ứng dụng khác bằng cách sử dụng mã này: [[UIApplication sharedApplication] openURL:appUrl];. Và tôi biết sơ đồ của URL để mở safari và thư, nhưng tôi đã thực hiện một số tìm kiếm và không tìm thấy gì về lược đồ của settings.app.có thể mở Cài đặt ứng dụng bằng cách sử dụng openURL không?

+1

thể trùng lặp của [Mở ứng dụng Settings từ một ứng dụng khác] (http://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app) – Flexo

+0

Tôi nghĩ [câu hỏi này] (http://stackoverflow.com/questions/377102/how-do-i-open-the-cài đặt-ứng dụng-fr om-my-application) trả lời nó. –

+1

Kiểm tra câu trả lời này: http://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked-ios/34024467#34024467 –

Trả lời

16

Bạn có thể sử dụng tính năng này trong các phiên bản iOS 5.0 - 5.0.1. Sau đó nó không được chấp nhận trong iOS 5.1 nữa.

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

Không còn hoạt động trong iOS 5.1. – mrueg

+0

mọi thứ dành cho> iOS 5.1? –

31

Bạn có thể mở các thiết lập các ứng dụng lập trình thử này (chỉ hoạt động từ iOS8 trở đi).

Nếu bạn đang sử dụng Swift:

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)) 

Nếu bạn đang sử dụng Objective-C

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 

Đối với phiên bản thấp hơn khác (ít hơn iOS8) của nó không thể programatically mở cài đặt ứng dụng .

+0

Ngón tay cái to lên! Điều đó thật tuyệt. Tôi đã thử nghiệm trên iOS 7.1 và ứng dụng này đã gặp phải sự cố, khi chạy iOS 8, bạn sẽ cần đến Cài đặt của Apple –

+7

là có cách mở ứng dụng Cài đặt chung (cấp cao nhất), không được khoan xuống Cài đặt ứng dụng của riêng bạn ? – zonabi

3

thiết lập Mở ứng dụng lập trình có thể chỉ từ iOS 8. Vì vậy, sử dụng đoạn mã sau từ http://code-ios.blogspot.in/2014/10/opening-settings-app-from-another-app.html

if([CLLocationManager locationServicesEnabled]&& 
    [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) 
{ 
    //...Location service is enabled 
} 
else 
{ 
    if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0) 
    { 
    UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
    [curr1 show]; 
    } 
    else 
    { 
     UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil]; 
     curr2.tag=121; 
     [curr2 show]; 
    } 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
NSLog(@"buttonIndex:%d",buttonIndex); 

    if (alertView.tag == 121 && buttonIndex == 1) 
{ 
    //code for opening settings app in iOS 8 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 
} 
} 
+0

Mặc dù người dùng không có nhiều quyền kiểm soát đối với nó, bạn có thể muốn thêm một kiểm tra cho [CLLocationManager authorizationStatus]! = KCLAuthorizationStatusRestricted –

0

Swift 4 phiên bản:

if let url = URL(string: UIApplicationOpenSettingsURLString) { 
    UIApplication.shared.openURL(url) 
} 
Các vấn đề liên quan