Settings Bundle --> ChildPane DefaultValues

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Settings Bundle --> ChildPane DefaultValues

    Hallo miteinander :)

    Habe eine kleine Schwierigkeit entdeckt.

    Und zwar habe ich in meinem Settings.Bundle ChildPanes in denen Switches mit DefaulValue YES sind.

    Wenn ich nun mein App neu installiere auf dem iPad, werden diese DefaultValues nicht geladen.

    Ich muss erst in jedes ChildPane über die Settings einmal gehen, sodass ich die Switches sehe. Dann zurück in mein App und dann werden die Values richtig geladen.

    Habe ich irgendwas übersehen, sodass die Settings am Anfang nicht geladen werden, obwohl se default auf YES sind?

    So lese ich die Variablen aus den Settings ein:

    Quellcode

    1. NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    2. BOOL *seat1 = (BOOL*)[user boolForKey:@"seat1_switch"];
    3. BOOL *seat2 = (BOOL*)[user boolForKey:@"seat2_switch"];
    4. BOOL *seat3 = (BOOL*)[user boolForKey:@"seat3_switch"];
    5. BOOL *seat4 = (BOOL*)[user boolForKey:@"seat4_switch"];
    6. BOOL *seat5 = (BOOL*)[user boolForKey:@"seat5_switch"];
    7. BOOL *seat6 = (BOOL*)[user boolForKey:@"seat6_switch"];
    8. BOOL *seat7 = (BOOL*)[user boolForKey:@"seat7_switch"];
    9. BOOL *seat1Comfort = (BOOL*)[user boolForKey:@"switch_comfort1"];
    10. BOOL *seat1Clima = (BOOL*)[user boolForKey:@"switch_clima1"];
    11. BOOL *seat1ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange1"];
    12. BOOL *seat2Clima = (BOOL*)[user boolForKey:@"switch_clima2"];
    13. BOOL *seat2Comfort = (BOOL*)[user boolForKey:@"switch_comfort2"];
    14. BOOL *seat2ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange2"];
    15. BOOL *seat3Clima = (BOOL*)[user boolForKey:@"switch_clima3"];
    16. BOOL *seat3Comfort = (BOOL*)[user boolForKey:@"switch_comfort3"];
    17. BOOL *seat3ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange3"];
    18. BOOL *seat4Clima = (BOOL*)[user boolForKey:@"switch_clima4"];
    19. BOOL *seat4Comfort = (BOOL*)[user boolForKey:@"switch_comfort4"];
    20. BOOL *seat4ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange4"];
    21. BOOL *seat5Clima = (BOOL*)[user boolForKey:@"switch_clima5"];
    22. BOOL *seat5Comfort = (BOOL*)[user boolForKey:@"switch_comfort5"];
    23. BOOL *seat5ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange5"];
    24. BOOL *seat6Clima = (BOOL*)[user boolForKey:@"switch_clima6"];
    25. BOOL *seat6Comfort = (BOOL*)[user boolForKey:@"switch_comfort6"];
    26. BOOL *seat6ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange6"];
    27. BOOL *seat7Clima = (BOOL*)[user boolForKey:@"switch_clima7"];
    28. BOOL *seat7Comfort = (BOOL*)[user boolForKey:@"switch_comfort7"];
    29. BOOL *seat7ComfortChange = (BOOL*)[user boolForKey:@"switch_comfortchange7"];
    Alles anzeigen



    Wobei die BOOLS seat1Comfort usw aus dem Childpanes zu seat1 usw kommen.
    Vielen Danke Klist
  • Ich bin da auch mal drüber gestolpert und löse das Problem, indem ich beim App Start das untenstehende registerDefaults aufrufe.

    Viele Grüße,
    Thomas

    Quellcode

    1. - (void)registerDefaultsFromSettingsBundle:(NSString *) settingsBundle withFileName:(NSString*)fileName {
    2. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    3. NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:fileName]];
    4. NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
    5. for(NSDictionary *prefSpecification in preferences) {
    6. NSString *key = [prefSpecification objectForKey:@"Key"];
    7. NSObject *defaultValue = [prefSpecification objectForKey:@"DefaultValue"];
    8. if (key) {
    9. NSObject *currentValue = [defaults objectForKey:key];
    10. if(!currentValue && defaultValue) {
    11. [defaults setObject:defaultValue forKey:key];
    12. }
    13. }
    14. NSString *type = [prefSpecification objectForKey:@"Type"];
    15. if ([type isEqualToString:@"PSChildPaneSpecifier"]) {
    16. NSString *file = [prefSpecification objectForKey:@"File"];
    17. if (file) {
    18. [self registerDefaultsFromSettingsBundle:settingsBundle withFileName:[NSString stringWithFormat:@"%@.plist",file]];
    19. }
    20. }
    21. }
    22. [defaults synchronize];
    23. }
    24. - (void)registerDefaults {
    25. NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    26. if(!settingsBundle) {
    27. NSLog(@"Could not find Settings.bundle");
    28. return;
    29. }
    30. [self registerDefaultsFromSettingsBundle:settingsBundle withFileName:@"Root.plist"];
    31. }
    Alles anzeigen
  • @Thallus

    Nein ich setzte die States der Settings erst beim Klicken eines Buttons.

    Also es ist ein button, wenn der geklickt wird, liest er die settings und wendet sie danach an.

    Ich versuche es mal indem ich sie schon im viewDidAppear aufrufe!

    Vielen Dank

    Und Teegemm, wenn die erste Version nichts hilft, versuche ich das mal :)

    Danke Klist