Why has Xcode 6.1 killed [NSLocale preferredLanguages] in IOS 8 simulators - xcode6

Yesterday Xcode updated to v6.1.
Now, [NSLocale preferredLanguages] is returning an empty array in the iPhone, but only for IOS 8 - both in iPhone 5 and 6 emulators. IOS 7 simulators are still working fine.
A physical iPhone 6 device doesn't appear to be affected - it's just the simulators.
The usual attempts - clean project, restart Xcode, reboot Mac - have made no difference. So, what's the best strategy - wait for Xcode 6.1.1, or send a complaint to an Apple list (which one) ?

You can use category with currentLocale method swizzling as described in here. The category allows one to override in general language and region settings in the project for all targets at once.
Also you can use scheme settings for each target in separate way.
If you have many localizations in your app,
you can change Application language and Application region in scheme settings for each target. You can even make a separate target for each localization for faster language tests.
Product -> Scheme -> Edit scheme...

I've flagged this for consideration as a dupe. Global preferences aren't working in the iOS 8.1 simulator. Localization is one such global preference. See:
See iOS8.1 Simulator always uses US keyboard layout despite german hardware keyboard
As for "strategy" ... you could just note that it's a known issue documented in the release notes and wait for a fix, or you can file a radar at http://bugreport.apple.com

First, they're simulators and not emulators. Second, I'm not seeing an empty array returned for [NSLocale preferredLanguages] under Xcode 6.1 (6A1052c) and any iOS 8.1 simulator, but I do always see "en" returned regardless of the language selected in the system settings. I do see correct behavior for any iOS 7 simulator, as you note.
I would file a bug complaint if one hasn't already been filed: more info at Changing language on iOS 8.1 simulator does not work.

Setting Product -> Scheme -> Preferences... didn't helped me, so I made a simple workaround:
NSString *language = [[NSLocale preferredLanguages] count] > 0 ?
[[NSLocale preferredLanguages] objectAtIndex:0] :
#"en";

Related

How to get all PHAssets from MacOS's Photo Library

I want to parse all images from my MacOS Photos Library, using PHAsset. However all examples I find are only working for iOS, like the one below, where the last line, which retrieves the assets is not available on macos framework:
NSMutableArray *photos = [[NSMutableArray alloc] init];
PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init];
allPhotosOptions.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:#"creationDate" ascending:YES]];
// Below compilation error as fetchAssetsWithMediaType is only on iOS framework
PHFetchResult *allPhotos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
What fetchAssets command should I use on MacOS (version 10.13), or is there another way to do so ?
The Photos framework — or at least, the main subset of that framework, which provides apps with read/write access to the entire Photos library — is not available in macOS.
Photos and PhotosUI are present in macOS, but only in support of specific app-extension features:
Photo Editing extensions. The user invokes these from the Photos app while in Edit mode for a single asset, and it provides direct access to the photo/video data for that asset, so it doesn’t even use the PHAsset class.
Photo Project extensions. These involve collections of assets and selectively loading data for each, so more of the PHAsset/PHImageManager system is present. However, it’s still a reduced subset compared to iOS (only what’s needed for a project extension, like fetching the assets in that project), and it’s accessible only to app extensions, not standalone apps.
If you’d like the full Photos framework on macOS, your best bet is to file a feature request with Apple.
As of macOS 10.15 Catalina, the Photos and PhotosUI frameworks are now available on the Mac, for both Catalyst and AppKit apps. So you should be able to transfer almost all iOS code that uses PhotoKit over to your Mac app now, as long as it has 10.15 as a minimum system requirement.

iOS iPhone iPad Simulator

This is what I get when I test my iPhone code on iPadPro 12.9 inch 2nd generation simulator. Isn't there a discrepancy ? Thanks, David.
I would highly recommend using this UIDeviceHardware instead of checking the interface idiom:
https://github.com/fahrulazmi/UIDeviceHardware/blob/master/UIDeviceHardware.m
NSString *platformString = [UIDeviceHardware platformString];
I've been using it for awhile now, and it works perfectly for me.
However, there is a problem when using it on simulator. When running on simulator, the platform is equal to x86_64 or i386 which will simply return iPad or iPhone. So ... I feel like you won't find a satisfying conclusion unless you tested this on a real device or at least got someone to test it for you on a real device.
In your case, you would check for one of these two platform strings:
"iPad Pro 12.9-inch (WiFi)" or "iPad Pro 12.9-inch (Cellular)"
https://github.com/fahrulazmi/UIDeviceHardware/blob/master/UIDeviceHardware.m#L83-L84
A good way to check for those is to just check for the prefix:
[platforString hasPrefix:"iPad Pro 12.9-inch"]

CSIndexErrorDomain error -1005

I am getting this error "The operation couldn’t be completed. (CSIndexErrorDomain error -1005.)" while running code for spotlight search on ipad.Does anyone know how to solve this error?
The CoreSpotlight is available on iOS 9 onwards.
Though your device maybe at iOS 9.x, it still may not work if it is a older device version.
From Apple docs.
Although app search is available for iOS 9 users, the search functionality of NSUserActivity and Core Spotlight is not supported on iPhone 4s, iPad 2, iPad (3rd generation), iPad mini, and iPod touch (5th generation)."
So if you are testing on any of the above devices or simulators for the same you will get the CSIndexErrorDomain error -1005.
From Corespotlight API documentation
CSIndexErrorCodeIndexingUnsupported = -1005, //Indexing isn't
supported on this device
Since the Search feature is not available on all the devices supporting iOS9 so check the following condition to know whether the device supports search
if ([CSSearchableIndex isIndexingAvailable])
and keep the methods of search under this condition.

Including iOS 6 properties in an object for an iOS 4.3 backwards-compatible app?

I'm adding some iOS 6 features to an existing app -- specifically, the built-in facebook integration. However, I need my app to retain backwards compatibility with iOS 4.3.
In most code, I understand how to handle this using respondsToSelector; I also understand to weakly link the Social and Accounts frameworks so they're only loaded if available.
What I don't know, though, is this: In order to enable the Facebook integration, I need to add a property to my "ShareViewController" -- which handles all the sharing for my app -- to hold the composition sheet, i.e.:
SLComposeViewController *mySLComposerSheet;
However, SLComposeViewController is a class that exists only in iOS6. So essentially, I need that property only to exist if the user is running iOS 6.
How does one handle this sort of situation?
It will just work. There's some metadata in the property/ivar that references the class name, but it doesn't actually link against the class or cause an error at runtime.
Of course, always test!
I suggest you use NSClassFromString and [UIDevice isSystemVersionHigherOrEqualTo:#"6.0"].

How do i migrate an app to iOS 5? (or turn on ARC)

I've got an app i'm working on and i just started using iOS 5. I'd like to start using Automatic Reference Counting but I'm not sure what steps i need to take to either migrate to iOS 5 or at least to turn on ARC.
If you look in Edit > Refactor menu, you'll see an option called Migrate to Objective-C ARC. That tool will help convert your code to ARC.
iOS 5 docs are not publically viewable yet, but in your Xcode you can go to the Organizer and view documentation. Search for "Programming with ARC Release Notes" and there's a document in there which will hopefully answer most of the questions you have about the process.