【问题标题】:iOS UIAlertView button to go to Setting AppiOS UIAlertView 按钮转到设置应用程序
【发布时间】:2012-02-23 21:58:52
【问题描述】:

有没有办法让 UIAlertView 的按钮转到调用它的特定应用程序的设置应用程序?

谢谢

【问题讨论】:

    标签: ios uialertview settings.bundle


    【解决方案1】:

    例如:

    NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
    [[UIApplication sharedApplication] openURL:url];
    

    [font=]
    About — prefs:root=General&path=About
    Accessibility — prefs:root=General&path=ACCESSIBILITY
    Airplane Mode On — prefs:root=AIRPLANE_MODE
    Auto-Lock — prefs:root=General&path=AUTOLOCK
    Brightness — prefs:root=Brightness
    Bluetooth — prefs:root=General&path=Bluetooth
    Date & Time — prefs:root=General&path=DATE_AND_TIME
    FaceTime — prefs:root=FACETIME
    General — prefs:root=General
    Keyboard — prefs:root=General&path=Keyboard
    iCloud — prefs:root=CASTLE
    iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
    International — prefs:root=General&path=INTERNATIONAL
    Location Services — prefs:root=LOCATION_SERVICES
    Music — prefs:root=MUSIC
    Music Equalizer — prefs:root=MUSIC&path=EQ
    Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
    Network — prefs:root=General&path=Network
    Nike + iPod — prefs:root=NIKE_PLUS_IPOD
    Notes — prefs:root=NOTES
    Notification — prefs:root=NOTIFICATIONS_ID
    Phone — prefs:root=Phone
    Photos — prefs:root=Photos
    Profile — prefs:root=General&path=ManagedConfigurationList
    Reset — prefs:root=General&path=Reset
    Safari — prefs:root=Safari
    Siri — prefs:root=General&path=Assistant
    Sounds — prefs:root=Sounds
    Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
    Store — prefs:root=STORE
    Twitter — prefs:root=TWITTER
    Usage — prefs:root=General&path=USAGE
    VPN — prefs:root=General&path=Network/VPN
    Wallpaper — prefs:root=Wallpaper
    Wi-Fi — prefs:root=WIFI`
    prefs:root=INTERNET_TETHERING
    

    【讨论】:

    • 我正在测试它,并意识到它只能在 ios 5 上运行。我在 iPhone 3G 上测试它,而不是 S。我知道它的旧大声笑。 iOS 4有办法吗?还是仅限于支持 iOS 5 多任务处理的设备?
    • 是的,如果您在 URL 类型中添加一个值为 'prefs' 的新项目,它可以在 ios6 和 ios7 中使用。我在ios7中测试过。
    【解决方案2】:

    只能从 iOS 8 以编程方式打开设置应用程序。因此,请使用以下代码...

    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]];
     }
    }
    

    【讨论】:

    • 是否可以转到设置应用程序的常规顶级,而不是您应用程序的设置选项?
    • 不,@zonabi,iOS SDK 没有为此提供任何选项。
    【解决方案3】:

    显然,这在 iOS 5.1 中不起作用。折腾了一上午,然后跑到了这个博客

    http://www.alexcurylo.com/blog/2011/11/04/settings-urls/

    【讨论】:

      【解决方案4】:

      在ios5及以上...

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

      【讨论】:

      • 苹果会批准这种打开设置应用的方式吗?
      • 工作正常 - 但您需要设置您的 url 类型以打开首选项:i.stack.imgur.com/Nq6qQ.png
      【解决方案5】:

      它也适用于 iOS8+,但我们需要改变一些东西

      NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
      if([[UIApplication sharedApplication] canOpenURL:url]){
          [[UIApplication sharedApplication] openURL:url];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-21
        • 1970-01-01
        • 2014-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-28
        相关资源
        最近更新 更多