In my app's today extension, I want to get some text from the main app. I tried using NSUserDefault and Notification, nothing I could get. I don't want to copy the same lengthy code from the main app, so how could I do? Thanks!
Asked
Active
Viewed 1,110 times
0
-
add target for extension in main files that could be used in extensions – Konstantin Kryzhanovsky Aug 04 '15 at 07:14
-
Enabled App groups? How you are accessing NSUserDefault? – Anil Varghese Aug 04 '15 at 07:16
-
@AnilVarghese I can't add app group because i'm not enrolled developer program, is threre another way to share data ? – ImWH Aug 04 '15 at 07:23
-
No other way. This is the only way to share data between App & extension – Anil Varghese Aug 04 '15 at 07:32
-
1if you can get the data from extension ,i mean if it is from a server, you can add the the server controller class to the extension target. – Anil Varghese Aug 04 '15 at 07:35
-
@AnilVarghese Thanks, It works. – ImWH Aug 04 '15 at 08:11
2 Answers
2
Create Apps Groups Under Targets->Capabilities as shown in below screenshot,it should be unique
Now u can store info NSUserDefaults
,but u have to use different methods for storing info with app groups name.Below i have given an example
NSUserDefaults *sharedDefault= [[NSUserDefaults alloc] initWithSuiteName:@"group.DigitalAnniversaries"]
[sharedDefault setValue:@"3" forKey:@"notification"]

Anil Varghese
- 42,757
- 9
- 93
- 110

Mukesh
- 3,680
- 1
- 15
- 32
-
I can't add app group because my ID is not enrolled developer program, is threre another way to share data ? – ImWH Aug 04 '15 at 07:25
1
If you enrolled Apple Developer program, the app group is a good way,or build a new target to share the data.