CFBundleURLTypes doesn't change - iphone

I'm currently trying to change the value of CFBundleURLTypes in the .plist file to a new value but it seems that nothing has an effect and the old value is still present if I call
NSLog(#"%#", [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleURLTypes"]);
I searched the whole project for the old value but the old value is nowhere present. I cleaned the project twice but it doesn't have an effect. Does the suppurted URL Schemes get cached somewhere?
Thanks for your help

It's not cached; the main bundle is read-only on iOS, because changing it would invalidate the signature. Possibly barring jailbreaking, I don't think there's a way to alter the Info plist after deployment.

Solved it. Problem was that I added an extra target to the app and the extra .plist for the target was not included in the project, so changes doesn't had an effect.

Related

How to Localize NSPhotoLibraryUsageDescription key (ALAssets)

I'm trying to localize the NSPhotoLibraryUsageDescription key defined in the application's info.plist file (reference here).
This key gives you a point to provide custom message when the app is first asking for access to your camera roll.
I'm using ALAssetsLibrary to enumerate assets groups (which triggers the access request message to pop-up).
So far my googling doesn't answer how I could achieve this.
I want to avoid localizing the whole info.plist file as it contain a lot more non-locale dependent content.
Anyone already solved this or have hints how to proceed?
There is a file you can create (which may be created for you when you create a project) called InfoPlist.strings. This file is used and localized much like the file Localizable.strings.
In it you would have and entry something like:
NSPhotoLibraryUsageDescription = "Test of new Photos warnings";
Note that there are no quotation marks around the key
I think as long as the key is included in info.plist, it will localized using the value in InfoPlist.string if it is available for the language. Otherwise it will use whatever is defined in info.plist.
I have my note here https://github.com/onmyway133/notes/issues/290, or you will get
Missing Info.plist key - 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.
Once these issues have been corrected, you can then redeliver the corrected binary.
Make sure
You declare the keys in Info.plist
You localize it in InfoPlist.strings
You don't need double quotes, like "NSPhotoLibraryUsageDescription" = "Test of new Photos warnings";, you can just use NSPhotoLibraryUsageDescription = "Test of new Photos warnings";
The only way to make this work for me was in Xcode to:
1) Go to Project target -> Info-> Localization-> Add localization
Added language there. This operation created the <projectName>/<LanguageInitials>.lproj folder.
2) I created file InfoPlist.strings inside the folder <projectName>/<LanguageInitials>.lproj;
3) I added the text:
NSPhotoLibraryUsageDescription = "<Add your translated text here>";
inside that InfoPlist.strings file.
4) I then added that folder to the project with File -> add new files to the project or drag and drop.
Note: to test this I:
Cleaned cache, set the language on simulator to be the new one, edited the language in scheme to be the new one at running on simulator and restarted the simulator.

My recently posted app update doesn't have latest/correct values in the info.plist file

I have a part in my info.plist file that stores a key metric that the app uses to know how many db's it can expect to load. It is a simple number that I change as needed. For some reason, when the app updates from the App Store with new values, it is as if the updated plist values aren't there. The app is working based on the old values.
But if I remove the application completely, and then reinstall from the App Store, it works! What am I missing here? Why wouldn't the plist file be updating correctly with an update? Is there some sort of manual copy/update process I should be doing to the Documents directory or something?
Can you write code of how you are accessing data from info.plist.
Also, remember when you are storing any data in documents directory, it will not update until you make it forcefully.
And info.plist always gets update once you update you build.
Hope it helps....

iPhone: updated info.plist value not being read

I have an app that when first launched reads in its data from a local XML file and is then archived for subsequent loads.
In future app updates its envisioned that this XML file might be updated with more data. To determine if I should re-load the XML data I have placed a custom key/value (a version number for the XML file) in the info.plist.
Now when I update the version number from 1.0 to 1.1 in the plist file, the app still reads it as 1.0. I'm guessing there is some kind of caching going on. Is there a way I can get the updated version on each load?
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* version = [infoDict objectForKey:#"IdeasVersionNumber"];
NSLog(#"version = %#",version); // always 1.0?!!
Is there a better method to do this? I didn't want to create a separate plist/XML file just to hold the version number as it seems like a waste of resources to load/parse these each time when the info.plist is always read.
Many thanks for any advice.
I am surprised by this behavior, but as it looks like the Info.plist is not always read, you might as well make a separate file for it. Or use NSUserDefaults.
A simple clean build did the trick! Thanks to #MCannon for the tip. I should have copped onto it.

Can't find momd file: Core Data problems

Aw geez! I screwed something up!
I'm a Core Data noob, working on my first iOS app. After much Stack Overflowing I'm using this code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"CoreData" ofType:#"momd"];
if (!path) {
path = [[NSBundle mainBundle] pathForResource:#"CoreData" ofType:#"mom"];
}
NSAssert(path != nil, #"Unable to find Resource in main bundle");
CoreData is the name of my app.
I've tried to put in initial data into the app by finding the path to the sqlite file in my iPhone simulator, and then going and inserting into that sqlite file. But at some point, I moved the sqlite (thinking it would create a fresh copy), deleted the app from the simulator, and the sqlite file is gone. I'm not sure if I'm leaving out some part of the process (this was a few hours ago) but the end result is that everything is screwed up.
How do I resubstantiate this sqlite / momd file? "Clean" and "Clean all targets" are grayed out.
I'm happy to post the relevant code from my app that would help shed some light on this problem but there's tons of code relating to Core Data which I don't understand, so I'm not sure what part to post! Any help is greatly appreciated.
Here are a few recommendations:
The code you posted to get the .mom(d) file is not exactly the recommended way. Use mergedModelFromBundles instead, as in
self.managedObjectContent= [NSManagedObjectModel mergedModelFromBundles:nil];
It takes care of getting the path, choosing/merging the correct mom or momd, and initializing of the MOC all by one step. You should use this. But note that you need to clean the build process once in a while, as discussed in this SO question/answer.
This shows that, although crawling through StackOverflow is often good, that's not the best approach when you deal with a big framework like CoreData.
Honestly, take a day and read the documentation from the start to the end. You might want to google bits of code and to start coding immediately, but reading through the documentation definitely saves the development time considerably in the long run.
Also, Marcus Zarra's CoreData book (see here) helped me a lot. It might look expensive, but it was totally worth while.
On a different topic, I don't think it a good strategy to put the pre-cooked sqlite file into the simulator's directory (inside ~/Library/Application Support/iPhone Simulator/) even for development purpose... because it doesn't work on the real device. If you need to do so, put the sqlite file as a resource of the app, and copy it at the launch time to either Documents or Caches, and use that afterwards.
If the clean targets menu items are grey, it could be that you have the app running.
The way you're getting the path to the mom/momd looks like you've tried to integrate CoreData after the fact (rather than opting to have it included when you created the project). I had the same issues as you probably do. The default code that looks for momd assumes it exists, and you should be able to, as well, if you add a version of your data model to the project.
To do that, select the xcdatamodel file, and in the Design menu select Data Model > Add Model Version. Then, you'll have CoreData.xcdatamodeld with a subtree containing Coredata.xcdatamodel and a new version. You can just delete the extra version and you'll have the hierarchy you need. If you build and look in the App bundle, you'll see the CoreData.momd directory with the mom inside.
Those steps aren't included in any of the CoreData tutorials I've found so far. I hope it's helpful!
Practical answer:
You might try the following code if you're having path issues. You'll also want to check that your xcdatamodel file is included as a resource for your target.
[[NSBundle bundleForClass:[self class]] pathForResource:#"CoreData" ofType:#"momd"]
Better answer: There's a distinction between a momd file, which represents your NSManagedObjectModel, and a sqlite file, which is used by your NSPersistentStore object. The best approach to working with CoreData is to let the SDK handle all the interaction with sqlite. The only thing you should need to set up regarding sqlite is telling your NSPersistantStore where to stash your sqlite file. The managed objects that you define in your managed object model will handle all the data insertion and updates for you.
If you're not familiar with the objects I've referenced, check out the apple docs for a very helpful overview. You'll definitely want to take the time to grasp the full CoreData stack, as the time investment will pay off in far less headaches if you work with Core Data the way Apple expects. It is a more abstracted design than many web developers are accustomed to, but trying to circumvent that abstraction by working directly with SQLite creates its own set of complexity.
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdBasics.html#//apple_ref/doc/uid/TP40001650-TP1
I found it very valuable to go look at my executable in the simulator "disk image".
If you head into ~/Library/Application Support/iPhone Simulator//Applications, you can see the apps on the phone. Figure out which one is yours (use find, or look at the date), and then browse into your target.app and look for the .momd file.
In my case, my momd name was different from my .xcdatamodeld file name, which was why core data couldn't load it. Once I corrected the name in the AppDelegate things started working correctly.
Note that the momd "file" seems to actually be a directory (like the .app setup).
--
In terms of adding the code to initialise core data; I did this too. I created a new blank project with core data enabled, and copied over all the initialisation steps for core data in the AppDelegate file. There's a whole bunch of stuff related to initialising the whole stack, so if that is not present, you need to put it there.
If you added a version to your model, change .mom to .momd
NSString *path = [[NSBundle mainBundle] pathForResource:#"CoreData" ofType:#"momd"];
if (!path) {
path = [[NSBundle mainBundle] pathForResource:#"CoreData" ofType:#"momd"];

iPhone MoveMe Example - trouble with DisplayStrings

I'm starting to play a bit with iPhone applications and I downloaded the MoveMe example from the apple web page.
I managed to run the app, however I do not get the strings displayed. I noticed that the DisplayStrings.strings file, although it exists in the app folder, does not appear as one of the resources.
I tried adding it as a resource, but then after compiling I get an error saying "copystrings failed with exit code 1". I cannot find anything online regarding what the origin of this problem is...
The file itself is in utf16 (big endian), and contains simply a list of strings separated by new lines.
Any ideas?
Thanks.
I was having the same problem and as a workaround I renamed DisplayStrings.strings to DisplayStrings.data and added it as a resource. I then modified init in PlacardView.m to use the new filename. This made Xcode happy.
I fixed this by adding the DisplayStrings.strings file as a resource. However, when you do this it defaults the type to 'text.plist.strings' which is incorrect, since the file is just text. So, right click on the DisplayStrings.strings file in resources and change the type to 'text'. This solved the problem for me.