Application UUID changes with app update in iOS - ios

I am storing path of downloaded file in sqlite db and when I update the app, its UUID changes but data doesn't get moved to new container. So the path is essentially invalid now. I checked if files still exist using iExplorer and they do.
platform.Is("iOS"){
this.localdirectory = this.file.dataDirectory+filename;
}
else
{
this.localdirectory = this.file.externalDataDirectory+filename;
}

A better approach to store UUIDs that need to be persistent between App installs would be to use the Keychain.
The keychain will not only persist between updates - but also between app installations. In fact - you can even remove the app altogether and it's still there.
Only completely setting up the device from scratch will actually give you a new value.
There is a gotcha (depending on how you build you Keychain domain) that different Provisioning profiles might get a new keychain (but old one still remains).
I do suggest using an open source to manage the keychain itself btw. It's really ... how should I put it ... different than a lot of modern code and conventions.
Also note - you can even use iCloud keychain in case you want to share across devices , and Appgroups to share among apps on the same phone.

Related

iOS wont delete my App Data after uninstall of MAUI Application

I am using MAUI.Essentials to store data in secure storage.
SecureStorage.SetAsync(key, securedValue);
But uninstalling the Application in android is deleting app data but the same is not working in iOS.
According to this post we need to turn off the backup in iCloud.
I am currently testing in iPhone simulator and under settings I have not logged in to iCloud.
Also I tried below code to manually delete the app data
if (VersionTracking.IsFirstLaunchEver)
{
services.AppCache.Clear();
}
But I don't want to delete it manually.
Any help is appreciated!
Given that (by iOS design) there isn't any way to delete data from iOS secure storage when app is deleted, you'll want a way to detect that there is "obsolete" data there, if the app gets deleted then re-installed.
When you detect this, you can decide whether to ignore or delete that "obsolete" data, so that it isn't visible to the new installation. Thus, it is as if it was not kept (other than the slight waste of storage -- never put anything large into secure storage).
I do this by creating an empty file in app local (not secure) storage, at the same time as saving the data to secure storage.
When app starts up, I check if that empty file exists. If it is not there, then I know anything in secure storage is "obsolete", left over from a previous install of app, so I erase it (if I don't want it to be visible when re-install).
Note that this also handles the case where user goes to Settings, finds the app, and does "Delete Data". Even if they don't uninstall app, the next time it runs, it will act as if it is a new install.
In the Maui official document (Secure storage) wrote:
KeyChain is used to store values securely on iOS devices. The
SecRecord used to store the value has a Service value set to
[YOUR-APP-BUNDLE-ID].microsoft.maui.essentials.preferences.
In some cases, KeyChain data is synchronized with iCloud, and
uninstalling the application may not remove the secure values from
user devices.
You can try to turn off iCloud with a real device, iCloud cannot be used in the simulator. You also can let the app start to call the delete code in your question to determine whether it is the first installation to delete the data in the KeyChain.

Why is a new project with the same app ID still designated a new location?

We have created a new project with the same app ID, but this is designated a different folder in isolated storage. Why is this?
file:///Users/houman/Library/Developer/CoreSimulator/Devices/FBFFFF1E-B5C8-4541-AB4B-ED1657D43EB9/data/Containers/Data/Application/EB3A549F-1604-4E5C-8FBE-3076A3D581E5/Documents/
file:///Users/houman/Library/Developer/CoreSimulator/Devices/FBFFFF1E-B5C8-4541-AB4B-ED1657D43EB9/data/Containers/Data/Application/22E1E792-1F4F-4F05-B7D9-F61AD3624EE9/Documents/
Even though the apps share the same ID.
Since they don’t share the same location, no core data migration can take place.
Any advice please?
Update:
We have two apps in the AppStore and would like to combine the functionality. Hence the idea is to use the appID of the other app to push a new release from a separate project. We have the appID and right certificates, but the isolated storage seems to depend on something else than just appid. Without that a migration of existing data to the new system won't be possible. Alternatively we could copy and paste all files into the other project and go through lots of pain. That might make it possible.
I have seen this on my end - I believe (and could be wrong) that each simulator you run in gets its own folder on the disk. If you switch for iPhone 5 to iPhone 6s for example you may end up with a different folder.
I always actually (when running in the simulator) print out the on-disk location so that I can take a look at the sqlite file if i need to and recently (as of xcode7) i've noticed this directory change between runs - however in my case i tracked it down to changing simulator versions.
Mainly for security reasons. Every iOS application is placed in an application sandbox.
This not only refer to an application's sandbox directory in the file system, granting security by limiting the access to user data stored on the device, system services, and hardware.

iOS app updating process

Apologies if this has been asked before but I couldn't find anything specific to my situation..
I've been tasked with creating a new version of an app already on the market place.
Unfortunately, the client only has access to the binary and not the source code as the previous development team didn't provide this information.
The client has been unable to get in touch with the previous development team so I can assume getting a hold of the original source code is off the table.
I was wondering, in a case like this, how does the iOS upgrade procedure work?
As an additional question, is it possible for the new app to access the data stored by the old app and if so, can anyone point me in the right direction on how to go about doing this please?
Thank you!
To make the update you must have the same bundleIdentifier as the current version. This will be displayed in iTunes Connect.
To get the stored data, you should use a tool called iFunBox.
Here's a little tutorial on how you can do it:
Steps for using iFunBox
Download the current version of the app
You should also use the apps functions, so the app saves the data you wish to extract.
Connect your iDevice to your Mac/PC
Download and install iFunBox (link here: http://www.i-funbox.com)
Launch the program and navigate to your device
Press "User Applications", then your application
Find the data the app stores
The NSUserDefaults plist-file is located in "Library" -> "Preferences" and is called com.yourCompany.appName.plist
A lot of apps also stores files in yourApp/Documents/
You can also explore the apps folder and look for the data you need. Hope this helps :)
If you have access to the iTunes Connect account, with which this app was published the problem is not too large: you can update app with any binary that have the same application id (bundle identifier) and larger version number.
You definitely can have access to the data of previous version - either it's stored in NSUserDefaults or app Documents folder etc., but you should have a clue of its format (e.g. keys of NSUserDefaults) - some reverse engineering of binaries can help.
You must know the bundleIdentifier and use the same otherwise the apps wont update.
The version number must also be higher than the current one
Also the data saved in the old app can be read but you need to know in which format it is.

iOS Data Protection not working on already installed app

I want to turn on 'Data Protection' in my app. Also, I wanted to check whether it is working with existing apps since I did not use it initially. To test this I used developer provisioning profile. First I installed the previous app (DataProtection is off) in my pass code enabled device and made sure that user's documents are available in the Documents folder. Then I turned on Data Protection in my provisioning profile and rebuilt the app using that new profile. Then I installed it on top of the previous app. Then I locked the device and downloaded the app sandbox using Xcode and noticed that I can access sandbox without any problem. I did it several times, but sandbox is still accessible.
Then I deleted the app and freshly installed the app that I had Data Protection turned on. Then I downloaded the app sandbox and I noticed that all folders in the sandbox including Documents folder are empty.
That means Data protection working only on freshly installed app. Am I doing anything wrong? I want to turn on Data Protection on my existing apps as well. How can I achieve this?
Since I didn't get enough attention to this question I posted it to apple developer forum. What they suggest was after enabling data protection If We are going to update the app (without deleting old app) we should explicitly set data protection for all files including old ones.
So what I did was loop through my document folder and set data protection attribute to all my old files.
Also I set data protection attributes in all places where I create new files. That solves my problem.
So the bottom line is If you are going to enable data protection in your old app better to do it explicitly.

Can I use iCloud to sync the NSUserDefaults plist file

I was wondering if it was possible to use iCloud to sync an app's preferences file between devices. The preference file I am talking about is the com.domain.appname.plist file created by NSUserDafults to store the app's preferences.
I would like to have the option of keeping my app's preferences file in sync between two different devices (an iPad and an iPhone, for example). Is this an acceptable use of iCloud syncing? Or would I need to convert the plist file into a different type of document, store it on the cloud, and convert it back into the app's preferences file upon retrieving it?
thanks!
Similar to MKiCloudSync, I also have a library on GitHub called SDCloudDefaults. Rather than sync automatically, there's a new object that you use instead of NSUserDefaults that saves to both iCloud and NSUserDefaults. This means you can decide which elements are stored locally and which are stored in the cloud.
(I found MKiCloudSync after I'd implemented it. I think it's clever but I don't want to sync everything to iCloud so my solution still works better for me.)
There is a library available to do this with one line of code
https://github.com/MugunthKumar/MKiCloudSync
It is possible to sync preferences between devices using iCloud. However, I would recommend against sharing the plist file between devices.
The NSUbiquitousKeyValueStore should be suitable for what you trying to do. It is very similar to NSUserDefaults, so it should be easy to pick up.
To use it, simply enable the com.apple.developer.ubiquity-kvstore-identifier entitlement in your entitlements file and just duplicate the preferences you like to sync in the ubiquitous key value store. Once it's in the ubiquitous kvstore, you'll be able to see it from the application on other devices. You can even sync between different applications as long as they use the same identifier.
You should also register for the NSUbiquitousKeyValueStoreDidChangeExternallyNotification notification to watch for new changes and update the standardUserDefaults on the device accordingly.

Resources