nsuserdefaults

NSUserDefaults won't save permanantly

廉价感情. 提交于 2019-12-13 04:46:27
问题 I have a fairly simple iPhone application that I am making. However, I cannot get my NSUserDefaults to save permanently. Writing and retrieving the data is not a problem––I can save the data (in my case, a string), and retrieve it on command, even after switching views, closing/opening the application, etc, and the data is retrieved just fine. It appears as if the string was saved properly to the key. But when I quit the application from the multitasking tray and restart it, the settings are

Initialize IOS Preferences from Preference Bundle on first App load

雨燕双飞 提交于 2019-12-13 04:40:57
问题 In my AppDelegate.m I'm trying to initialize the default values from my Preference Bundle if the user hasn't gone to the settings pane yet. The initialize runs, and I see the correct number of objects for my preferences but they're all null and nothing gets set. + (void)initialize { NSLog(@"Running settings initialization"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];

iOS WatchKit - Adding Key Value Observer to NSUserDefaults crashes

倖福魔咒の 提交于 2019-12-13 04:27:38
问题 I am trying to add the ability to send data from iPhone to Watch. I have setup App Groups and everything runs smoothly, but when I try to add an observer to NSUserDefaults in the Watch Extension file, the app always crashes on startup. (And yes, I have verified that the app group name is correct and checked in all Target Capabilities AND all provisioning profiles are up-to-date with App Group enabled) Code: override func willActivate() { super.willActivate() NSUserDefaults(suiteName: "my

Countdown in Cocos2d

蓝咒 提交于 2019-12-13 04:23:36
问题 I am trying to think through how to implement a countdown on a stamina level. For example, maximum 100% and over time it decreases. I don't need to know how to display it but the technology behind it to get it working and where to look. This countdown would keep on going down when the application is closed. I was looking at NSUserDefaults as a means to do this. Is this correct? Similar to the top bar as shown below: 回答1: You can save latest refueled stamina value in NSUserDefaults or in

Store NSMutableSet to NSUserDefaults

心已入冬 提交于 2019-12-13 03:37:12
问题 I want to store a Swift Set in NSUserDefaults. Given that I can read a NSMutableSet value from UserDefaults using: UserDefaults.standard.mutableSetValue(forKey:) ... it seems like I should be able to write a NSMutableSet too. I tried converting my Set to NSMutableSet, but when I try to save it in UserDefaults it says: [User Defaults] Attempt to set a non-property-list object {( foo )} as an NSUserDefaults/CFPreferences value for key KEYNAME 回答1: mutableSetValue(forKey:) has an unfortunate

Save and Append an Array in UserDefaults from ImagePickerControllerImageURL in Swift

橙三吉。 提交于 2019-12-13 02:46:13
问题 I'm having an issue saving and retrieving an array in UserDefaults from UIImagePickerControllerImageURL. I can get the array after synchronizing, but I am unable to retrieve it. myArray is empty. The testImage.image does get the image, no problems there. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { let imageURL: URL = info[UIImagePickerControllerImageURL] as! URL //test that imagepicker is actually getting the image let

how to store a value in Phonegap apps, any way other than database

这一生的挚爱 提交于 2019-12-12 23:09:47
问题 hi friends i am a mobile developer. So far i have worked in iPhone apps and android apps. Now i am working in Phone gap based apps for iPhone and Android mobiles. Now my problem is in my app i have a log in page where i have to enter the username and password and i return i use to get a unique is and token which i have to use for the whole app. If the app gets closed and opened after a long time i want this to be remained same. For this in ios apps we use a method called UserDefault method

Archiving and Unarchiving results in Bad Access

耗尽温柔 提交于 2019-12-12 16:30:50
问题 I'm having trouble setting up a model object to save the visual state of user generated CALayers in a simple graphics application for the iphone. I'm attempting to save the background color and frame of all the current layers on screen by passing those properties to model objects which implement the NSCoding protocol and then into an NSMutableArray which the app delegate owns. Then I archive the array with NSKeyedArchiver and store it in the NSUserDefaults. Each CALayer's backgroundColor

Difference between core data & NSUserDefaults-notes app

心不动则不痛 提交于 2019-12-12 14:36:08
问题 Creating a budget app (not for release, just something quick & dirty) and I noticed upon starting the Master-Detail template that Apple uses Core Data and NSFetch results to populate the tables (think Notes on an iPad). My inexperienced and unprofessional programming instincts wouldn't think twice about grabbing an NSMutableArray, taking the names of the table cells and cramming them into an index, saving that as an NSUserDefault and then upon reloading the app, populate each cell at it's

Check for first launch of my application

蓝咒 提交于 2019-12-12 08:51:14
问题 How would I check if it is the first launch of of my application using NSUserDefaults and running some code for the first time my app opens? 回答1: This should point you in the right direction: static NSString* const hasRunAppOnceKey = @"hasRunAppOnceKey"; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; if ([defaults boolForKey:hasRunAppOnceKey] == NO) { // Some code you want to run on first use... [defaults setBool:YES forKey:hasRunAppOnceKey]; } 回答2: The NSUserDefaults