Be patient..... we are fetching your source code.
Objective
Main Objective of this blog post is to give you an idea of how to use AppsGroups in iOS 8
App Groups
Though AppExtension and its containing Application is in same Bundle they cannot directly communicate or share data, Even direct communication between iOS Applications also not possible. Here, AppGroups helps you. App Groups are used to share data between AppExtension and its containing application, and also helps to share data between different iOS applications.
Lets see how you can use AppGroups in your application.
Step 1 Create XCode Project
Open Xcode and create new project with single view application template as shown in below figure.
In the next step enter AppGroupDemo as a product name and also select Objective-C as a language as shown in below figure.
Step 2 On AppGroups
Go to capabilities and switch on AppGroups It will ask you to add your Apple ID account that is enrolled in a Developer Program.
Select Add.. and provide your AppleID and Password.
Step 3 Add AppGroup
Add AppGroup by clicking on + button it will ask you to enter group name.
Click Ok after adding group name then it will add “App Groups” entitlement in your entitlements file, add “App Groups” entitlement to your Apple ID and add “App Groups Containers” entitlement to your Apple ID.
Step 4 Share Data using App Group
In this demo example I have added a UITextField to get data from user, which can be shared to other application. For that…
Add UITextField and UIButton in ViewController in storyboard. Add action method of UIButton. In that method declare NSUserDefault object and provide your AppGroup name as suite name. Set UITextField text as value for particular key lets say UserName.
- (IBAction)btnShareClicked:(id)sender
{
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.tag.testGroupDemo"];
[myDefaults setValue:self.txtName.text forKey:@"UserName"];
self.txtName.text = @"";
}
Step 5 Display Shared Data in Other App
Create other Application to receive shared data.
*Note :- perform Step:1, Step:2 and Step:3 to create other application and add AppGroup in that application. You can see list of all AppGroups select your AppGroup from which you want to access data.
Now create NSUserDefault object and provide AppGroup name as suite name and you can access data using valueForKey as below.
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.tag.testGroupDemo"];
self.lblUserName.text = [NSString stringWithFormat:@"Hello, %@", [myDefaults valueForKey:@"UserName"]];
I hope this blog is very helpful while App Groups in iOS 8. Let me know if you have any problem or questions regarding iOS 8 please comment here. I will reply you ASAP
Got an Idea of iPhone App Development ? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best iOS App Development Company in India
I am iOS developer with an aspiration of learning new technology and creating a bright future in Information Technology.
Integrating Media Player in iOS Using Swift