ios - NSUserDefaults in App Groups Not Working -
i trying use app groups entitlement in app nsuserdefaults handling data between iphone app , watchkit extension.
i went capabilities in iphone target, , turned on app groups, , made sure group.com.316apps.iprayed selected. went watchkit extension target , did same capabilities.
on iphone side of app put in following code:
pfuser *me2 = [pfuser currentuser]; nslog(@"username%@", me2.username); nsuserdefaults *testdefaults = [[nsuserdefaults alloc] initwithsuitename:@"group.com.316apps.iprayed"]; [testdefaults setobject:me2.username forkey:@"username"]; [testdefaults setobject:me2.password forkey:@"password"]; [testdefaults synchronize];
in watchkit interfacecontroller, have following, nslog shows 'null'
nsuserdefaults *testdefaults = [[nsuserdefaults alloc] initwithsuitename:@"group.com.316apps.iprayed"]; nsstring *theiruser = [testdefaults objectforkey:@"username"]; nsstring *theirpass = [testdefaults objectforkey:@"password"]; nslog(@"%@", theiruser);
why watchkit not reading nsuserdefaults properly?
note bundle identifier different watch kit extension target. need new apple id that?
it ok bundle identifiers not same, should in format
the app bundle id -> com.companyname.productname extension bundle id -> com.companyname.productname.extensionname
if follow formats above refer answer below
you need add observer knows when value in nsuserdefaults
has changed.
refer code:
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(userdefaultsdidchange:) name:nsuserdefaultsdidchangenotification object:nil];
Comments
Post a Comment