Get the similar timezone list as in iphone Settings app - iphone

I am able to get list of timezones using
NSArray *timezoneNames = [NSTimeZone knownTimeZoneNames] ;
but the generated list of timezones does not cover all the major city names. Like for India it shows only Kolkata city. While I expected to display the timezone for New Delhi (capital) also.
So I want to generate the same timezones list as iOS generates in its Settings->General->Date Time-> Timezone because it shows almost all the major cities of the world. Can we fetch this list? Or do we need to create our own database(say .plist) for this?

Settings.app uses a plist file to display the timezone list. The name of file is: "all_cities_adj.plist".
To get to this file you need to traverse deep down into the SDK itself.
I have mentioned the traverse path below where you can find it.
1.Go to the folder where you have your Xcode.
2.Right-Click on it and then click Show Package Contents.
3.Then Contents --> Developer --> Platforms --> iPhoneSimulator.platform --> Developer --> SDKs --> iPhoneSimulator6.1.sdk --> System --> Library --> PrivateFrameworks --> AppSupport.framework
4.In this folder you can find the plist file.
Please let me know if it helped...

I've been running into this problem as well and there is no way to get the same timezones as in the settings app.
You will need to create you own list.

Firstly you need to download the .csv file which will provide you country/cities/timezone/region. Using this file we can display the list of countries and their cities. When user select any city we need to map it with the respected country and then this country needs to be map with device's timezones([NSTimeZone knownTimeZoneNames];).
This link also might be useful in this regard:
Get timezone by Country and Region

Related

How do you create files in arbitrary locations using Swift?

How do you go about creating files at arbitrary locations given you have the absolute path? I want to create a file in some arbitrary location /Users/me/random/project3/<moreStuffInThePath. How would I go about doing this?
To create a directory I would do:
try FileManager.default.createDirectory(atPath: "/Users/me/random/project3/<directoryName>"
This worked fine for directories.
However the counterpart for creating files does not work:
FileManager.default.createFile(atPath: "Users/me/random/project3/something.txt", contents: someString.data(using: .utf8)) // always returns false
I have checked out other stack overflow threads on creating files. Everything I found was about creating files in the .documentDirectory or it was outdated.
Eg: How to create text file for writing
Create empty file swift
Read and write a String from text file
TLDR: How do I create text files/files with random extensions at arbitrary locations on the pc given I have the absolute path?
I would also be grateful if someone could explain why all tutorials available on this matter are about the document directory. Why is it so significant?
Thank you!
This is most likely because your app is sandboxed.
Go to your project settings, select the macOS target and go to "Signing and Capabilities". You should see something like this:
If your app needs to create files in arbitrary locations, you must remove the app sandbox by clicking on the "x" on the top right. Note that this will cause your app to be rejected from the Mac App Store.
If you want to upload your app to the Mac App Store, then you must keep the sandbox, and write to "user selected locations" only. Select "Read/Write" rather than "Read Only" next to "User Selected File". (Although it says "File", this includes directories too) This allows you to write to locations chosen by a user using something like an NSSavePanel.

iOS sort files in folder by date added

My app downloads files from the internet.
App stores them in Documents folder .
App uses iTunes Sharing feature, and user can store files in Documents folder through iTunes (when my application is launched and when my app is not launched).
In one of tableviews in my app I want to present files from Documents directory sorted by Date added (date, when files were added to Documents directory).
Is there any file attribute like "Date Added" on iOS?
How can I retrieve it?
I searched for this, but I cannot found an answer for now.
I think I can save the date for downloaded files and files that were added through iTunes when my app was launched, using DirectoryWatcher.
But I don't know how can I get the "date added" for files that were stored in Documents through iTunes when my app was not launched.
How can I do this?
I know that there is Arrange by Date Added in Finder on Mac OS 10.7. How they do it?
Thank you.
Yes you can use NSFileManager to do this, you can give it a file path to request a dictionary of attributes, one being the modification date
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDictionary/fileModificationDate
I found that file does not contain Date Added in its attributes.
After copying files through iTunes Connect from mac to app creation date and modification date remains unchanged (as they were on the mac).
Also I found that Finder on Mac uses external sqlite database ~/Library/Preferences/com.apple.dock.db for storing Date Added attribute.
So for my needs I have decided to use some kind of external database for storing "date added" value.
I think I will use NSUserDefaults, and I will use filename and inode number as a key.

Find location by inputting a zipcode on an iPhone application

I hope someone can help or at least point me in the right direction. I'm currently building an iPhone application that requires the input of a zip code to find a location. For example - if the user opens the app the first thing they see is a text box that requires them to input a 5 digit number (zip code) to find various businesses near that location. There is also a slider bar that has 5mi to 100mi radius. So, once the zip code input and the user has selected how much mileage and pressed the submit button, it should show the lists of businesses that are local to that area. Does that make sense?
Thanks a bunch everyone.
First of all zip code does not map specifically to one location . It may refer to disjoint sets of location as well (this happens in India ) One zip code like 400093 refers to diffrent place in India and might refer some different location in Korea . There is no central server which could provide you with these specification. check for google API (check here for google API) to look for alternatives .
For your use case I would suggest you to look Four square API. get user co-ordinates , use geo location to detect their place or directly call four square api to get the useful information.
FourSqaure API
You can do this in your app, or make a web-service that will get the imput zip code and return the region.
It's a huge work. In couple of words:
Make a plist file that will have as keys all the zip codes you can load into it. Take a look here, they are not few. And set the values as the region names.
Once you have the zip code, you can find the region. Then, depending on the user's selected range, you can present the closest regions.
Also look here, for detailed explanation of zip codes' formatting. You will have to learn a bit in order to be able to detect closest regions of a selected zip code.
As a fast, but not secure way - you can find a free web service that does the job (takes zip, gives region), without building your own server-side (or method in the app), but as I said, it's not secure.
Work.

How do I remove support for English in my iOS app?

I renamed en.lproj to sv.lproj. I then added the Swedish resources to the project and removed the English resources.
The problem is that the app still "thinks" that it supports English, i.e. [[NSBundle mainBundle] localizations] returns both en and sv.
I've removed every reference to en and English that I could find in the project file and the info plist, but it still supports English.
I'm running out of ideas, so please help me. There must be a ton of people that written apps that doesn't support English. Still I haven't been able to find anything useful on Google.
First of all check this:
List item
Open project in Xcode >= 4.0.2
Click on project file
Select item under Project title on the right
Check Localizations table.
EDIT: Adding the final steps to solve my problem in case anyone has the same problem. /Erik B
Select the localization you want to duplicate (English)
Click + and select the language you want you're app to use (Swedish)
Select the localization you want to remove (English)
Click - and delete the files
That's all there's to it. Now your app will only use Swedish or whatever language you chose.
First go to project details (first entry in the project navigator) and click on your project to see the global settings. Look what is written under "Localizations". If there is still "English" you have to check for every file what is in the file inspector under Localization. Remove every English localization.

iphone app programming: existing plist file for time zones?

Is there a plist file that lists the timezones and maybe a corresponding city? Being able to select a couple of time zones (independent of the users location/iphone settings) is a requirement in an application I am writing.
I am hoping I don't have to reformat some existing list into a plist.
Thanks,
Mike.
There is an API that will pull all that time zone information for you. Check out the Tableview Suite sample code
http://developer.apple.com/iphone/library/samplecode/TableViewSuite/index.html