NSUserDefault with App Group is not working in iOS 8 Beta3
Asked Answered
P

2

3

I have to save Boolean Value to NSUserDefault in my App with custom keyboard extension and share with App Group.

My Code is worked in iOS 8 Beta1.

self.defaults = [NSUserDefaults standardUserDefaults];

if([self.defaults boolForKey:@"BlackKey"])
    {
        NSLog(@"Black");
    }

    else
    {
        NSLog(@"White");
    }

But Not in iOS 8 Beta3. When i retrieve Boolean value from NSUserDefault , it's return nothing and i can't load from custom keyboard extension.

I have also tried with initWithSuiteName in NSUserDefault. Am i only one for that problem or bugs of iOS 8 Beta3?

Paugh answered 19/7, 2014 at 13:35 Comment(0)
H
2

A few probable solutions are:

  1. Your app group is not setup correctly, or you are not using the correct group identifier with initWithSuiteName:

  2. You have not enabled network access for your keyboard. This document states the following when you have network access disabled for your keyboard (default behavior):

    No shared container with containing app

  3. It's a bug.

Heteroousian answered 19/7, 2014 at 21:58 Comment(2)
So you mean , i have to enable RequestsOpenAccess to use NSUserDefault?Paugh
Looks like this is fixed in beta 5Lauber
H
-5

Try using

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"BlackKey"];

when you save and read it by using this code:

if([[NSUserDefaults standardUserDefaults] boolForKey:@"BlackKey"]) {
    NSLog(@"Black");
}

else
{
    NSLog(@"White");
}

or if you already done so, then it can be bug, and Xcode 6 beta versions also have other bugs so it's safer to try in Xcode 5 or older.

Huckaby answered 19/7, 2014 at 13:44 Comment(1)
It's not work. You should say iOS 8 Beta and iOS7. Not XCode 8 Beta. :DPaugh

© 2022 - 2024 — McMap. All rights reserved.