0

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!

Vidya Sagar
  • 1,699
  • 3
  • 17
  • 28
ImWH
  • 820
  • 1
  • 7
  • 20

2 Answers2

2

Create Apps Groups Under Targets->Capabilities as shown in below screenshot,it should be uniqueenter image description here

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.