in iOS7 [[NSUserDefaults standardUserDefaults] objectForKey:#"AppleLanguages"] gave me an array of all languages. as of iOS8 this seems to have changed to the installed keyboards.
how can i still get an array of all languages in iOS8?
Use +[NSLocale preferredLanguages] instead of querying NSUserDefaults. Note that as mentioned in the Xcode 6.1 release notes, there is a known bug in the iOS 8.1 simulator runtime that prevents this from working there, but this will work as expected on other simulator versions and on device.
If you want a list of all supported languages rather than just the user's preferred ones, you can use +[NSLocale availableLocaleIdentifiers] which will return an NSArray of all supported locale identifiers.
Related
Recently I submitted my app on AppStore with a method setting badgecolor of tabbaritem.
[[[AppDelegate globalDelegate].tabBarController viewControllers] objectAtIndex:1].tabBarItem.badgeColor = kTabBarBadgeColor;
This badgeColor came in iOS 10 only and my app supported iOS 8 and above. I had no idea about it and the app got approved. Now, I have to resubmit my app with fixing this issue.
I want to know if there is a way to find out such cases where methods get deprecated or are visible in specific OS versions only.
By changing target of Xcode project you can see errors & warnings while building.
If you need more info,
You can visible all API changes like Added,Modified & Deprecated variants in Apple documentation
it will give you searching options for both Swift & Objective C
Searching UITabBarItem Instance Property badgeColor. it gives API changes are none.Supporting SDK's version
SDKs
iOS 10.0+
tvOS 10.0+
Searching finishedSelectedImage instance method of UITabBarItem.
SDK
iOS 5.0–7.0 Deprecated
Deprecated Use selectedImage with UIImageRenderingModeAlwaysOriginal
instead.
In my app, I would like to know if the user has setup a passcode or fingerprint (touchID). There's a pretty easy method just for that: [LAContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:error].
However, Apple's docs say LAPolicyDeviceOwnerAuthentication is only available on iOS9 and above. I would rather not crash iOS 8 users without explanation, even if it is getting older. The thing is, I've tried it on an iOS8.4 simulator, and it seems to compile and just work.
What ill effects can happen if I use LAPolicyDeviceOwnerAuthentication on iOS 8?
I use code similar to this:
LAPolicy localAuthPolicy = LAPolicyDeviceOwnerAuthenticationWithBiometrics;
if (![[UIDevice currentDevice].systemVersion hasPrefix:#"8."]) {
localAuthPolicy = LAPolicyDeviceOwnerAuthentication;
}
This ensures I only use LAPolicyDeviceOwnerAuthentication on iOS 9 and later.
It's undocumented what actually happens on an iOS 8 device when you attempt to use LAPolicyDeviceOwnerAuthentication. It's very unlikely anything will crash but the authentication may return NO due to an unknown value or it may succeed because iOS 8 only had one valid value and it may not do any checking.
Unfortunately Objective-C doesn't provide any runtime checks for valid enum values like you can do with constants, methods, and classes.
If you use LAPolicyDeviceOwnerAuthentication on anything below iOS 9, the app will crash. That is what happened to my app when I didn't realize that this was not available on anything below iOS 9, but my app supported iOS 8.x as its minimum supported OS version.
In the app I can choose in the settings which language of three should be used. If nothing is selected, the iPhone language is detected and selected for english, french or german. If none of this languages is the iPhone language, english is set to be used. Manually changing the language in the settings works as it should. Now I added a today-extension which works nearly well but I need to access the settings-bundle to get the NSUserDefaults for the languages (if manually changed). In both targets I activated the App-Groups with
group.com.companyname.appname
and selected it.
In the app I get the language with
NSString *manualLanguageSet = [[NSUserDefaults standardUserDefaults] valueForKey:SPRACHWAHL];
and in the today-extension I try to get it by:
NSString *manualLanguageSet = [[[NSUserDefaults alloc] initWithSuiteName:#"group.com.companyname.appname"] valueForKey:SPRACHWAHL];
For NSLog(#"Settings-Sprache: %#", manualLanguageSet); when running the today-extension the result is (doesn't matter if and which language is selected in the settings)
2014-09-13 16:48:36.331 HdB today[3734:284836] Settings-Sprache: (null)
What can I do it correct / how can I access to the settings (settings.bundle)?
If you create a WatchKit preferences bundle, it also contains the key
ApplicationGroupContainerIdentifier
at the root level of dictionary of the bundle's Root.plist, with the value being the group identifier (what you provide to NSUserDefaults as suiteName).
I found that you can also use this key in the iOS settings bundle. If added, preferences will go to the respective container.
I verified this to work on iOS 8.3 across the iOS Settings app, the iPhone app and the WatchKit extension.
UPDATE: Apple lists this key as supported in iOS 8.2 and later at
https://developer.apple.com/library/ios/documentation/PreferenceSettings/Conceptual/SettingsApplicationSchemaReference/Articles/RootContent.html
I'm searching for it as well. The only way i know how to do it is via SharedContainer. In your example you should open your
[[[NSUserDefaults alloc] initWithSuiteName:#"group.com.companyname.appname"] valueForKey:SPRACHWAHL];
in container app and then copy the language value from NSUserDefaults of container app like this :
[[[NSUserDefaults alloc] initWithSuiteName:#"group.com.companyname.appname"] setObject:[NSUserDesaults standardUserDefaults] objectForKey:SPRACHWAHL] forKEY:#"Your Key in extension"]];
then you will be able to access your shared container in you extension and get those values.
If someone have a better way of doing it i would be happy to know as well.
I have a problem retrieving my locale currency symbol.
NSString *currencySymbol = [[NSLocale currentLocale]
objectForKey:NSLocaleCurrencySymbol];
I was expecting the £, instead I still get the $.
In my system settings the region is already set to United Kingdom.
What am I missing please?
UPDATE: I just realised, if I deploy the app on the iPhone, the symbol shows correctly. It is only the simulator that still shows the Dollar sign instead of the Pound.
Alright, I found the answer. I was expecting the simulator to retrieve the locale of my Mac which is United Kingdom. However the simulator is completely isolated in its own sandbox.
Hence you need to change the settings on the simulated iPhone to United Kingdom. Then you have to kill the application process in the simulated iPhone itself and restart the application. Surprisingly the simulator keeps the new iPhone settings after a restart.
Now it works. I hope this helps someone else with a similar problem.
I have a Mac program that stores its data using NSKeyedArchiver. I'm using the same code in an iOS app to try to read in the data from the file, but it crashes when trying to decode an instance of NSAttributedString. Are the iOS and OS X versions of NSAttributedString compatible, i.e. is this a bug in iOS?
If not, is there anything I can do short of modifying the Mac app? I'd prefer not to have to do that, for compatibility reasons.
NSAttributedString may look identical on both iOS and OS X, some of
its properties are not.
You are correct see: http://lists.apple.com/archives/cocoa-dev/2010/Aug/msg00479.html
NSFont vs UIFont etc.
So I'm not confident in this answer without going in depth into the documentation, but whilst NSAttributedString may look identical on both iOS and OS X, some of its properties are not. For example, NSString has additions that differ both on iOS (UIStringDrawing.h) and Mac OS.
It could be to do with the decoder on iOS encountering or expecting data to be in the archive that doesn't exist. Could you paste the logs you get? Normally if a keyed archiver encounters an error it will log the problem to the console.