Ans :
If we ever needed to share data between your iOS apps and/or your application targets/extension/widgets , there’s a very easy way to do this using app groups. App group capability introduced with iOS 8.
We can make file observer to be notified for changing value instantly. We can put observer on userdefault.plist file and being notified for some value changed in other application.
Note : BBPortal is example of this.
If we ever needed to share data between your iOS apps and/or your application targets/extension/widgets , there’s a very easy way to do this using app groups. App group capability introduced with iOS 8.
To do so, we can enable the 'App Group' Capability.
- In Xcode’s Project Navigator, Click the 'Project Icon'
- Select the 'Host App' Target
- Select the 'Capabilities' Tab on the top menu
- Toggle the 'App Groups' capability
- If you have not associated a development team you will be prompted to. - Select '+' icon and enter a unique group name such as 'group.reverse.company.uri.name'
- Repeat the above for the Extension’s target
You can then use NSUserDefaults initWithSuiteName:.
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.app"];
Then set a value in one target…
[sharedDefaults setObject:value forKey:@"key"];
[sharedDefaults synchronize];
And read the associated value in the other target…
NSString *value = [sharedDefaults stringForKey:@"key"];
We can make file observer to be notified for changing value instantly. We can put observer on userdefault.plist file and being notified for some value changed in other application.
Note : BBPortal is example of this.
No comments:
Post a Comment
Thanks