3 Replies
      Latest reply on Jun 7, 2019 8:49 AM by eskimo
      KhanhND Level 1 Level 1 (0 points)

        Dear all,

         

        I'm facing a very weird problem, when I'm working in Develope mode, I can get value from extension OK.

        But when in Distributed mode or Ad Hoc mode, when I archive to an iPA file. I can't get value from extension.

        I don't know why this happend. And It just happend recently. Is anyone meet the same problem with me ?

        • Re: NSUserDefaults stringForKey cannot get value in distribute or Ad Hoc mode
          eskimo Apple Staff Apple Staff (11,825 points)

          Are you trying to share user defaults between your app and your app extension via a shared app group?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: NSUserDefaults stringForKey cannot get value in distribute or Ad Hoc mode
              KhanhND Level 1 Level 1 (0 points)

              Hi Mr eskimo,

              Yes, I shared my data between my app and my app extenstion via a shared app group. When I deploy it directly to device, It work well and I can get data when I open app via app extension. But when I distribute it and export it to iPA or push it to test flight, it doesn't work, I can't get data I need, it seem connect with other SuiteName. I guest that the app group was automatic changed when in distribution mode. But I don't know what it is.

               

              NOTICE: I'm just facing this problem after recently update provisioning.

               

              Below is example of my source code, please help me to check it.

              ```

              #define GROUPID @"group.com.****"

               

              std::string NVDataManagerNative::getString(const std::string& key, const std::string& def)

              {

                  NSUserDefaults *ud = [[NSUserDefaults alloc] initWithSuiteName:GROUPID];

                  if(ud == nil){

                      ud = [NSUserDefaults standardUserDefaults];

                  }

               

                  NSString *ret = [ud stringForKey:convertNSString(key)];

                  if (nil == ret) {

                      return def;

                  }

               

                  return [ret UTF8String];

              }

               

              bool NVDataManagerNative::putString(const std::string& key, const std::string& value)

              {

                  NSUserDefaults *ud = [[NSUserDefaults alloc] initWithSuiteName:GROUPID];

                  if(ud == nil){

                      ud = [NSUserDefaults standardUserDefaults];

                  }

                  [ud setObject:convertNSString(value) forKey:convertNSString(key)];

                  [ud synchronize];

                  return true;

              }

                • Re: NSUserDefaults stringForKey cannot get value in distribute or Ad Hoc mode
                  eskimo Apple Staff Apple Staff (11,825 points)

                  Its sound like your have entitlement issues.  You should dump the entitlements of your built binary to make sure it has the appropriate entries in the com.apple.security.application-groups property.

                  $ codesign -d --entitlements :- /path/to/your.app

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"