0

Hello I'm working on something where I need to pass some data from a target to another (basically an app to another) and I red that App Groups is the way to do it .
I've made a class to manage that .

class PaywallHelper {
static let sharedDefaults = UserDefaults.init(suiteName: "group.Myapp")!

var tokenForPaywall: String? {
    get {
        return PaywallHelper.sharedDefaults.string(forKey: "user_token")
    }
    set {
        PaywallHelper.sharedDefaults.setValue(newValue, forKey: "user_token")
        PaywallHelper.sharedDefaults.synchronize()
    }
}

var ad_id: Int? {
    get {
        return PaywallHelper.sharedDefaults.integer(forKey: "id")
    }
    set {
        PaywallHelper.sharedDefaults.setValue(newValue, forKey: "id")
        PaywallHelper.sharedDefaults.synchronize()
    }
}

var category_id: Int? {
    get {
        return PaywallHelper.sharedDefaults.integer(forKey: "category_id")
    }
    set {
        PaywallHelper.sharedDefaults.setValue(newValue, forKey: "category_id")
        PaywallHelper.sharedDefaults.synchronize()
    }
}

also I have enabled the App Groups from Capabilities ...but what botheres me here is that it is red... ..

The thing is it is working fine on simulator I receive the data and i can work with them...as for the real device it s not working...What am I doing wrong?

enter image description here

Mohamed Lee
  • 267
  • 1
  • 3
  • 18
  • 2
    Not related but why is `ad_id` and `category_id` declared as optional? `integer(forKey:` does **never** return an optional. And here's another *never*: **Never** use `setValue(:forKey` when setting a value to `UserDefaults`. Use `set(newValue, forKey...`. – vadian Apr 19 '18 at 13:58

1 Answers1

0

Usually the app group being red means that the provisioning profile associated with your app doesn't have the same capabilities/entitlements.

When you add the app group, if you were connected to the internet and have automatic signing on, it should be add to your provision profile on the developer portal for you. If you were not connected to the internet or don't have automatic signing setup then you'll have to add the app group capability to you provision profile yourself via the developer portal.

Taylor2412
  • 36
  • 6