Settings.bundle not respecting app group on iOS simulator or device - nsuserdefaults

I had been using standardUserDefaults until recently but decided to use shared app groups because I created a watch extension. I have set up an app group and also added the ApplicationGroupContainerIdentifier to the settings bundle.
I have spent hours on this and, even after reading many articles, I just can’t get this to work. I am seeing that when I alloc my app group and print its contents, it has default values from standardUserDefaults.
All I am doing is [[NSUserDefaults alloc] initWithSuiteName: SUITE_NAME]] and then print its contents on the very next line.
I am puzzled by how it has values from my settings bundle. Moreover, when you edit the properties using the settings app, the settings in standardUserDefaults are changing but my app group values stay the same.
I see the same behaviour on the simulator and real device.

This turned out to be user error. There was a typo in the app group name as a result of the auto-correct feature. I did not realize it until I created a new app group.

Related

Catalyst app info.plist not being recognized

I am trying to submit my first catalyst app to the Mac App Store. I have setup the App Store information in iTunes Connect, and I have confirmed that the info.plist in app has the following key in it:
<key>LSApplicationCategory</key>
<string>public.app-category.business</string>
However when I go to upload to the app store I get the message that I need to add the LSApplicationCategory
ERROR ITMS-90242: "The product archive is invalid. The Info.plist must contain a LSApplicationCategoryType key, whose value is the UTI for a valid category. For more details, see "Submitting your Mac apps to the App Store"."
I have confirmed that both public.app-category.business is correct, and I have also tried using the value "Business". I get the same error message. Is there something else I need to look at?
The key which you are adding to .plist file is wrong. Add below key-value pair. Full list here.
<key>LSApplicationCategoryType</key>
<string>public.app-category.business</string>
slicerdicer's recommendation worked for me. To add some additional detail, you can also set the App Category by going to Project / Targets / General. It's the very first option.
I had sucsessfuly upload two apps using catalyst then the third failed with that error. I found this and seemed to work.
To the info.plist add App Catagory with what ever catagory your app fits. I used Productivity.
I was converting an iOS app to a Mac app, and I was updating the file info.plist, and it was not actually updating the overarching project.
I ended up having to go to the overarching project, under the left side TARGETS tab, I selected my app, went to the Info tab, and added the App Category there.

WatchKit extension doesn't see updates to NSUserDefaults for App Group

I've seen a couple of questions on this, and tried all the answers provided, and this still isn't working for me.
I'm trying to share several small pieces of data (Strings and BOOLs) between my iPhone App and its WatchKit extension. (If it makes any difference, the info is being read by the GlanceController of the WK app)
Via the Developer site I created an App group (group.com.theYawns.Sorcerers-Apprentice). If I look at 'App IDs' there I appear to have two identical IDs for my app (com.theYawns.Sorcerers-Apprentice) plus one for the extension (com.theYawns.Sorcerers-Apprentice.watchkitextension). Each of these has 'App Group' enabled (for both Development and Distribution) and the app group is selected if I edit the App ID.
I've turned on 'App Groups' in capabilities for both the App and the Extension. A concern I have it that periodically -- several times a day but not every build -- if I go in and look at the Capabilities tab, I have a red exclamation point saying 'Add the App Groups' entitlement to your entitlements file. If I look at the entitlements file, the entitlement is there, and if I click 'Fix issue', the red exclamation point changes to a checkmark. But the fact this needs to be done multiple times per day concerns me that something is amiss.
I've refreshed my provisioning profiles under XCode preferences many times, and while I don't see an App Groups icon under entitlements, if I hover I do see app groups in the tooltip that pops up.
In both my app and extension, I get a reference to the user defaults via
NSUserDefaults *sharedAppDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.com.theYawns.Sorcerers-Apprentice"];
I've also tried adding a [sharedAppDefaults synchonize] after each write and before my WatchKit attempts to read, just in case things weren't being flushed out. (Didn't make any difference).
My WatchKit extension bundle id is different from my iPhone App bundle id, which is one of the answers I saw on a different thread.
I've also added an NSTimer to refresh the glance every 10 seconds, so if there was a timing issue with picking up the changes, I would expect it to resolve itself after an update cycle or two, but it does not.
Really stumped ... seems others have had their issue resolved by answers from the other threads but none have worked for me.
Other threads I've searched include:
Why won't app groups work inside my WatchKit extension?
https://stackoverflow.com/questions/27047455/how-to-shared-storage-between-app-and-extension-with-app-group-and-
WatchKit NSUserDefaults and NSKeyedUnarchiver issue
OK, I found an answer in the Apple developer forums.
It appeared, from the XCode target 'Capabilities' tab, that I had all the correct entitlements set. And I could see the 'Entitlements' file in my project, open it, and see that it was set up correctly.
BUT -- if I looked under my App Target's 'Build Settings' tab, in the 'Code Signing' section, there was no entitlements file shown. (It all shows up correctly for the WatchKit Extension but not for the main iPhone app).
When I plugged in the name of my entitlements file under Code Signing, everything started to work.
This seems like a bug to me -- I don't believe the 'Capabilities' tab and the 'Build Settings' tab of the same target should ever be looking in different places for entitlements. But wanted to post the answer that worked for me here in case anyone else runs into this.
Summary: to make sure entitlements are correct, you have to see the switches set properly in Capabilities, AND you have to see the entitlements file referenced under Build Settings / Code Signing.
You have to add the entitlement to your provisioning profile of app extension.To do this, Login to your developer account to add the entitlements, after this download the latest provisioning profile. To verify whether the app group has been enabled or not , open the downloaded provisioning profile in "TextEditor" and search for "app group". This will show you the result, if you have done it properly. Use these newly downloaded provisioning profiles ,and it will show you the check mark in capabilities.

InAppSettingKit custom bundle is not recognized on device

I set up InAppSettingsKit and wish to have only certain volatile settings available from within the app. These would not be the same as what is found in settings.app from springboard. I added a bundle, InAppSettings.Bundle and created the appropriate plist files. It works as expected in the simulator but acts as though my new bundle does not exist on the device. The device shows only the same as the settings.app properties in settings.bundle/ root.plist.
How do I get the new bundle into users' devices without deleting and reinstalling the app?
In this case, it was a "case" of developer error. Apparently the case of the characters in the name of a file are not specific in the simulator. The files in my bundle were not correctly named. I had root.inApp.plist when it should have been Root.inApp.plist. Worked in simulator,not on the device.
Once I realized this and renamed the file, the device read and displayed the correct file as intended.
That was a waste of about 5 hours chasing my tale. I Hope this info helps someone avoid this same annoying oversight.

Why can't our app store a simple key/value pair in iCloud?

I've configured our app for iCloud usage with the appropriate entitlements, under a provisioning profile that is set up for iCloud, and a developer profile that's associated with this provisioning profile.
The application identifier matches what's specified in the provisioning profile (com.ourcompany.ourproduct). I don't get any errors when building the app.
iCloud is enabled on my phone, and is working (as evidenced by my calendar, contacts, and bookmarks being updated).
And yet this fails (localID is a valid NSString):
NSUbiquitousKeyValueStore* iCloudStore = [NSUbiquitousKeyValueStore
defaultStore];
[iCloudStore setString:localID forKey:#"ourKey"];
If I call synchronize after this, it returns NO. If I allow plenty of
time for the update to occur, subsequent attempts to retrieve the data
still fail.
Any idea what the culprit could be here?
Thanks!
In the simulator, NSUbiquitousKeyValueStore will just store values on disk and won't even try to synchronize anything.
On the device, synchronize will generally fail because your kvstore-identifier entitlement is incorrectly set but you should then see an error log in your Console.
Are you running it in the simulator? iCloud sync doesn't appear to work in the simulator, only on a device. Beyond that, your code looks good. I would expect it to work.
I also noticed that I was able to store and retrieve keys even before I set up my entitlements. I'm assuming the entitlements just allow you to link a key-value store to your App ID so that multiple devices or multiple apps from your company can share a store.
Knowing this, you could try completely removing references to iCloud in your entitlements and see if that works. Just for testing purposes.

App Settings change: 2 synchronizes for StandardUserDefaults necessary?

I am changing app settings within my iPhone application.
Strangely, I have to do 2 synchronize commands with StandardUserDefaults to make my changes to be reflected in the app settings.
Secondly, when I change my "preferred user language" within my iPhone application, I do have to start my app twice for the language change.
What's the reason for that?
Is there a way to dump the StandardUserDefaults and to see all the settings stored there?
Thanks for your help!
Is there a way to dump the StandardUserDefaults and to see all the settings stored there?
Yes, that is pretty easy to do.
The NSUserDefaults are stored in a plist file located in your app's sandboxed environment inside the Library folder.
For checking this on the simulator, have a look at
~/Library/Application Support/iPhone
Simulator/5.0/Applications/[hashed app
identifier]/Library/Preferences/[application bundle identifier].plist
Note that you will have to replace the values in brackets to find your specific app. Also note that this path works for the iOS5.0 environment - for others, you will have to replace the 5.0 with whatever system version you are working with.