NSUserDefaults for App Groups
Since iOS 8 app developers are able to implement a communication between their apps (like an app with a widget). For example you want to change the settings of the widget within your app.
Actually the most developers are using therefore the "NSUserDefaults". But there is a difference between the normal and the "App Group" NSUserDefaults. Here´s an example:
NSUserDefaults for App Groups:
NSUserDefaults *SharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.example.AppGroupName"];
Standard NSUserDefaults:
NSUserDefaults *StandardDefaults = [NSUserDefaults standardUserDefaults];
Complete App Group Example
NSUserDefaults *AppGroupsExample = [[NSUserDefaults alloc] initWithSuiteName:@"group.appname.AppGroups"]; NSInteger Variable = [AppGroupsExample integerForKey:@"Test"]; Variable = 1; [AppGroupsExample setInteger:Variable forKey:@"Test"];
Important: In order to use NSUserDefaults for App Groups you need to register an "App Group" at the Apple Developer Center at the "Certificates, Identifiers & Profiles" page. Additionally you need to add the "App Group" option to your app (Select target > Capabilities > App Groups).
More Information about NSUserDefaults
If you have questions send me a mail to hi(at)developing.io.



















