Trouble with UserDefaults(suitename:) - ios

I'm writing an iOS app that includes a Messages extension. To share data between them I created an app group with a key similar to "group.com.myCompany.myApp". The app stores an array of strings using userDefaults.set(:forKey:). Then the app can fetch or modify the array, and the extension can fetch (but not modify) the array.
Both the app and the extension are accessing the UserDefaults using UserDefaults(suiteName:). Both the app and the extension are using the same value for the suite name.
The problem I'm having is that this works just fine in the simulator but on the phone the extension doesn't see the array of strings. I'm completely at a loss.

It's the entitlements!
Earlier, in response to a post that has since been deleted, I wrote "the entitlement files are correct as far as I can tell." When I wrote that a light bulb went off in my head: "The app group entitlement is missing, that's why it works in the simulator and not on the phone!"
I didn't realize that the entitlements have to be specified separately for Debug and Release builds, and I had not specified them for the Release build. Adding that took care of the problem.

Related

Opening Custom UTI in App not working in iOS13

I have been using AirDrop for ages now to allow a document to be passed from/to iPhone users from within my App. The App generates a straightforward CSV file which is then AirDropped (or could be emailed too) to another machine, where my App can open it and import it (the UTI is registered for the csv file type). This has been working fine for a long time, but I now see that devices running iOS13 no longer list my App as being able to import the file. If I run the same code on iOS12.4 (or earlier) it works fine, but on iOS13.1 my App is no longer registered to receive the data. The device can AirDrop to another device perfectly, and provided the destination is not iOS13 the import works fine. Whenever the destination is iOS13 my App simply is not listed as being available to receive. I can't see what might have changed.
The info settings (that work perfectly up until iOS13) are:
I cannot see anything in the iOS release notes that would suggest this has changed at all. Can anybody help with this?
Since you and your app didn't invent the CSV file type, you should use a standard UTI for CSV and not invent your own.
This means you should use the Imported UTIs section to declare the CSV UTI. The Export UTIs section should only be used by new UTIs that are unique to your app.
Here is my Imported UTI for CSV:
Here is my Document Type for CSV:
I have no trouble sending CSV files to my app under iOS 13 with these in place.
Also keep in mind that under iOS 13, you may need to tap on the "More" icon at the end of the list in the share sheet to see your app (and possibly others) as a choice.

Including application data in iOS simulator

I have an app that records and stores accelerometer data as core data managed objects. I would like to include some sample saved recordings in the simulator to test the app on different platforms, since the simulator cannot record from the accelerometer. I have successfully included *.xcappdata files in the build scheme and it works on devices, but simulator fetches come back empty.
Apple documentation seems to indicate that including app data in the simulator is possible but I have not gotten it to work. I have tested including data saved from one device on another device and that works fine. I am getting no error message, just an empty fetch.
I know I could include data in the form of text files in the app, read and format them upon launch, and save them as managed objects, but it would create a bunch of appendix code and files in the project, and I would rather work more cleanly.
You can find your application's data container path by running xcrun simctl get_app_container <device> <bundle identifier> data in a Terminal window. Device can be the name (quoted) or the UDID (see xcrun simctl list). For this to work, the relevant simulator will have to be running, and have a version of the app installed on it.
Right-click on the .appdata file to show the contents of package. Copy the core data files you got from Folders in AppData/* into the analogous directory then start your app in the Simulator.
Xcode does not currently have a GUI to manage containers in the Simulator like it does for physical devices. If you don't mind please file an enhancement request at https://bugreport.apple.com/ requesting this in the Devices & Simulators window.
I've just figured it out that, as a workaround at least for Xcode 9.2/iOS 11.2 simulator, you can set (HOME/CFFIXED_USER_HOME) (I'm not sure whether of those actually works) environment variables in launch arguments to a path to .xcappdata/AppData, like shown below (I used SRCROOT relative path just for illustration of possibilities - it works with any other kind of path like absolute ones and etc). Beware that the changes in the app data will be reflected right in that folder, so if you don't want that, it makes sense to point it to the copy.

Firebase Dynamic Links for iOS - Query Parameters are not passed through from iTunes Store

Hi we are using Dynamic Links on iOS and Android to pass though query parameters for various marketing and share links. The query parameters are passing through correctly on iOS when a user already has our app installed. However we are not seeing the query parameters come through or the specific dynamic links passed through to us on new iOS app installs that first travel through the iTunes store. We do not have this problem with Android via Google Play. Is this a known issue with Firebase on iTunes/iOS?
We have debugged our code on our end and are uncertain whether there is something different we need to do in the initialization of our code for brand new installs on iOS? It is also very difficult to test this out as it requires one to create a brand new production build and do an install from the App Store. In our testing we are uninstalling the app locally and then reinstalling from the app store. Note that since we have installed the app before, the app store shows a download from Cloud icon as the option even though we are installing the brand new version. We wonder if this perhaps is the issue?
Any help you can provide in debugging and solving this issue and any tips on how to test without going through the app store would be appreciated.
Can you check you have a custom URL scheme defined for your app (as well as the universal links that you've got working?)
The current way Dynamic Links is working is:
Store the parameters server side before redirecting to the app store
On startup, check if its first run. If so, check to see if there are matching server side paramters.
If there are, call openURL on a custom URL scheme matching your bundle ID (com.foo.bar etc.) and pass the parameters through
So, if the "first open" check is failing it wont do it, or if it can't pass through the parameters (due to missing custom URL scheme).

iTunes connect rejects my App after uploading because of missing privacy-access descriptions

I want to upload my app to iTunes connect but after uploading I always get an error message by mail from iTunes, that after their scan some description variables are missing.
This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
I am using both features, so that's ok, BUT: i already added those variables to my localized infoPlist.strings. And these seems to work, because in the Simulator and my iPhone, both strings are displayed correctly in the system dialogs. I didn't add the strings to the plist.info file, because I specified them in the localized file, which should be ok. The plist.info and also the localized file are both packaged in the app, I already head a look using Finder.
Is there anything else I must add? Do I still need to add them to the plist.info file, although they are in the localized file?
Additional info: I am using the latest XCode 8 GM build on macOS Safari.
Are you using AdMob? If so the answer is that Google confirmed that it is an issue with the AdMob SDK. You can read about it here.
The solution is, to add the keys also to the PList.info file, not only to the localized infoPlist.strings file.
This is a bit inconsequent because within the simulator and on my phone every message is displayed correctly. But now my app was accepted.

Prefixing iOS shared App Group with TeamId

tl;dr Does anyone prefix their shared App Group name with their TeamId?
We use an App Group for sharing data between our app and extension, and with another app of ours. I've been passing the suite name as "group.com.example" to NSUserDefaults -initWithSuiteName and NSFileManager -containerURLForSecurityApplicationGroupIdentifier and it's been working fine.
With iOS 10 I'm seeing an Xcode console error when starting my app:
[User Defaults] Failed to read values in CFPrefsPlistSource.
Using kCFPreferencesAnyUser with a container is only allowed for System Containers,
detaching from cfprefsd
A known solution is to prefix our TeamId to the group, but we already have an app out there using the non-prefixed variant, so changing it in this new app will cause compatibility issues. Other than this msg on startup there's no discernible problem.
Here's what makes me wary: We shipped a similar Mac app a few months ago and were hit with an App Store validation error that forced us to use the TeamID on the Mac:
Invalid Code Signing Entitlements. Your application bundle's signature
contains code signing entitlements that are not supported on Mac OS X.
Specifically, value '[group.com.example]' for key
'com.apple.security.application-groups' is not supported. This value
should be a string or an array of strings, each starting with
your TEAMID followed by a dot '.' .
Apple's docs and sample code don't mention the TeamID prefix at all, and my hunch is this isn't a change they'd be able to make without breaking a huge number of apps out there, but if this is a direction Apple is moving I'd rather deal with it now than later.
Does anyone have any authoritative knowledge about using the TeamID prefix or not on iOS? Anyone run into problems using it, or not?

Resources