nsuserdefaults

Adding custom language to the iOS app

北慕城南 提交于 2019-12-10 12:00:45
问题 I need to add a custom language (iOS has no localisation for it) among with support languages. A user is able to choose desired language in app settings (built-in screen, no in Settings app). I store it to NSUserDefaults : [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"lv"] forKey:@"AppleLanguages"]; Next time, when the app starts, it loads with selected language. And works great. But here is a 'small' issue. The app needs to be restarted. Thus, I need a way to

How do I check app connectivity correctly?

纵饮孤独 提交于 2019-12-10 11:59:02
问题 I'm trying to create a function to check the Connectivity when the App loads. If a internet connection is detected, the app should download the JSON data and save the array in UserDefaults, then proceed to the UITableView methods. However, if the internet connection is not found, the app should recover the array on USerDefault to populate another array, then proceed to UItableView methods. The problem I'm facing, is that when the compiler goes trough UserDefault line to be able to save the

how to retain my uitextfield values in viewController when i calling?

我的梦境 提交于 2019-12-10 11:54:18
问题 I have a main page having 3 textfield in my first view as i navigate to different view and return back to my first view (i.e after i enter all the values i moving to next page).I want my 3 textfield to retain its value when i go back to my main page here my sample code : NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *mobile = MobileNum.text; [defaults setObject:mobile forKey:self.MobileNum.text]; NSString *amountText = amount.text; [defaults setObject:amountText

How to maintain cell selection in NSUserDefaults?

亡梦爱人 提交于 2019-12-10 11:13:45
问题 https://github.com/lminhtm/LMDropdownView How can I save the last selected cell in NSUserDefault? When the application is reopened the selection should be maintained. Currently, the default cell is selected whenever the app opens. - (void)viewDidLoad { [super viewDidLoad]; self.mapTypes = @[@"Standard", @"Satellite", @"Hybrid"]; self.currentMapTypeIndex = 0; self.dropPinButton.layer.cornerRadius = 5; self.removeAllPinsButton.layer.cornerRadius = 5; self.moreButton.layer.cornerRadius = 5; self

Swift 3 / iOS 10 / TodayExtension - UserDefaults always returns nil

别说谁变了你拦得住时间么 提交于 2019-12-10 10:11:32
问题 This is my first Question on this site. I have a problem that I cannot fix. I'm working on an easy note application with today extension. I have had no problem in Swift 2.2 and iOS 9. Problem just appears in Swift 2.3 and Swift 3, on iOS 10. The problem I have is the following : User can write a note (saved in UserDefaults) and open Notification Center and watch his notes in a TodayExtension. I have these methods to save notes in UserDefaults and retrieve it from UserDefaults (I'm using

How to save a struct to NSUserDefaults in Objective-c?

安稳与你 提交于 2019-12-10 09:14:24
问题 How do I save a custom struct to NSUserDefaults ? struct Paging { NSInteger currentPage; NSInteger totalResults; NSInteger resultsPerPage; }; typedef struct Paging Paging; NSUserDefaults *userInfo = [NSUserDefaults standardUserDefaults]; [userInfo setStruct:paging forKey:@"paging"]; [userInfo synchronize]; The above code produces a run-time warning: *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value... 回答1: One way is to turn it into NSData NSData* d = [NSData

How do I save an Int array in Swift using NSUserDefaults?

被刻印的时光 ゝ 提交于 2019-12-10 05:46:54
问题 This is an array: var myArray = [1] It contains Int values. This is how I save an array in NSUserDefaults . This code seems to be working fine: NSUserDefaults.standardUserDefaults().setObject(myArray, forKey: "myArray") This is how I load an array: myArray = NSUserDefaults.standardUserDefaults().objectForKey("myArray") The code above, though, retrieves an error. Why? 回答1: You want to assign an AnyObject? to an array of Int s, beacuse objectForKey returns AnyObject? , so you should cast it to

How to use NSUserDefaults to store an array of custom classes in Swift?

廉价感情. 提交于 2019-12-10 03:28:59
问题 I have a custom class called Person that stores various attributes about someone when they enter information. class Person { // Person dictionary variable var name: String? var age: String? var html_url: String? init(json: NSDictionary) { // Dictionary object self.name = json["name"] as? String self.age = json["age"] as? String self.html_url = json["html_url"] as? String // Location of the JSON file } } Once the dictionary is created, it is then placed into an array. I am having problems

Detecting the initial launch of an app using NSUserDefaults

妖精的绣舞 提交于 2019-12-09 23:50:47
问题 In reference to the following question: iPhone: How do I detect when an app is launched for the first time? When I looked up NSUserDefaults apple reference, it said that registerDefaults does not store the data onto the disk. In the above question, the app registers the value firstLaunch to YES upon each launch. So each time the app is launched, firstLaunch is overwritten to YES and so the app will always think that this is the app's initial launch. Am I right on this? EDIT: After doing what

Reading preferences set by UIAutomation's UIAApplication.setPreferencesValueForKey() on the target device?

佐手、 提交于 2019-12-09 21:56:02
问题 Over the last few days I've been playing with Apple's UIAutomation framework in an attempt to try to put together a suite of acceptance tests to drive the development of an app I'm working on (in a BDD type way...). One thing I'm bumping up against is how to get the SUT into a given state so I can begin my tests if I need to set some internal state for that to happen. The problem is that Apple's Javascript environment doesn't provide any functionality I could use to communicate with the