使用openurl时,应用程序设置捆绑包未显示在设置应用程序中 [英] App settings bundle not showing up in settings app when using openurl

查看:83
本文介绍了使用openurl时,应用程序设置捆绑包未显示在设置应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动我的应用程序时,模式视图会显示给用户,并包含一个用于在设置"应用程序中调整设置的选项.如果选择此选项,则按如下方式使用openURL:

When my app launches, a modal view displays to the user and includes an option to adjust a setting in the Settings app. If this option is selected, I use openURL as follows:

if (&UIApplicationOpenSettingsURLString != NULL) {
        NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:appSettings];
}

这成功将用户重定向到设置"应用程序中我应用程序的设置.问题在于,向用户显示的唯一设置是使用蜂窝数据"单选按钮.我在root.plist中的设置在任何地方都找不到.在设置"应用程序中对该视图的所有后续访问中,所有root.plist设置均正确加载.

This successfully redirects the user to my app's settings in the Settings app. The problem is that the only setting that appears to the user is the "Use Cellular Data" radio button. My settings from the root.plist are nowhere to be found. In all subsequent visits to this view in the Settings app, the root.plist settings all load correctly.

我的理论是这是一个计时问题,由于某种原因,我的应用程序的root.plist尚未加载到设置"应用程序中.有谁知道是这样吗?我可以强迫它以某种方式加载吗?将用户定向到不存在的设置很尴尬且令人困惑.

My theory is that this is a timing issue and that my app's root.plist has not yet been loaded in the Settings app for some reason. Does anyone know if this is the case? Can I force it to load somehow? It's awkward and confusing to direct the user to non-existent settings.

推荐答案

在以下链接:

读取Root.plist的NSUserDafaults的值为零

有人指出在用户首次打开设置之前,settings.bundle中的值实际上不会加载到NSUserDefaults.默认情况下,它们是关闭的.用户打开设置包后,将为你."

Someone stated that "The values from settings.bundle do not actually load to NSUserDefaults until the user opens the settings for the first time. By default, they are off. Once the user opens the settings bundle, they will fill in for you."

我相信这里提出了一些解决方案:

and I believe some solutions were proposed here:

即使不打开设置"应用程序,也可以将Settings.bundle中的设置设为默认设置

例如@Lawrence Johnston的这个

Such as this one from @Lawrence Johnston

- (void)registerDefaultsFromSettingsBundle {
    [[NSUserDefaults standardUserDefaults] registerDefaults:[self defaultsFromPlistNamed:@"Root"]];
}

- (NSDictionary *)defaultsFromPlistNamed:(NSString *)plistName {
    NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    NSAssert(settingsBundle, @"Could not find Settings.bundle while loading defaults.");

    NSString *plistFullName = [NSString stringWithFormat:@"%@.plist", plistName];

    NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:plistFullName]];
    NSAssert1(settings, @"Could not load plist '%@' while loading defaults.", plistFullName);

    NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
    NSAssert1(preferences, @"Could not find preferences entry in plist '%@' while loading defaults.", plistFullName);

    NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
    for(NSDictionary *prefSpecification in preferences) {
        NSString *key = [prefSpecification objectForKey:@"Key"];
        id value = [prefSpecification objectForKey:@"DefaultValue"];
        if(key && value) {
            [defaults setObject:value forKey:key];
        } 

        NSString *type = [prefSpecification objectForKey:@"Type"];
        if ([type isEqualToString:@"PSChildPaneSpecifier"]) {
            NSString *file = [prefSpecification objectForKey:@"File"];
            NSAssert1(file, @"Unable to get child plist name from plist '%@'", plistFullName);
            [defaults addEntriesFromDictionary:[self defaultsFromPlistNamed:file]];
        }        
    }

    return defaults;
}

这篇关于使用openurl时,应用程序设置捆绑包未显示在设置应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆