nsuserdefaults

save bool in nsuserdefaults

和自甴很熟 提交于 2019-12-05 05:41:41
when my app starts music is playing: -(void)playBgMusic { NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"]; theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; theAudio.delegate = self; [theAudio play]; } but he should be able to turn the music off by pressing a button if he presses the button again the music should turn on again. i have: -(IBAction)check { if (isquiet == NO) { [theAudio stop]; isquiet = YES; defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:YES forKey:@"stringKey"]; } else { [self

iPhone - Save URL without setURL:forKey: and NSURL

无人久伴 提交于 2019-12-05 04:48:38
问题 Is there anyway to save a URL with NSUserDefaults without setURL:forKey: that is only available to iOS 4.0 and later? I am loading HTML files locally with fileURLWithPath, and it starts at an intro page and the user can click through to whatever. For now, everytime a user starts over it loads back default to intro.htm. I would like to be able to save their current page to NSUserDefaults on viewdiddissapear and reload it next time, but can't find any solutions besides setURL:forKey:. Anyone

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

﹥>﹥吖頭↗ 提交于 2019-12-05 04:09:54
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 saving the array into NSUserDefaults when a button is tapped. personArray.append(newPerson) // newPerson =

NSUserDefaults and iOS framework / library

一笑奈何 提交于 2019-12-05 02:15:37
I have recently been building an app using [NSUserDefaults standartdUserDefaults] to store locally various information (regarding the session, user preferences, etc). Now I am exporting a subpart of my project as an iOS framework (the goal is to make a SDK). I am generating a MyKit.framework and MyKit.bundle to be imported in third party apps (the bundle contains Storyboards, Localizable.strings and .xcassets). For the moment, I made sure that resources used by MyKit.framework are loaded from the MyKit.bundle scope and not the [NSBundle mainBundle] to avoid collisions with resources from the

NSUserDefaults in iOS Playground

半腔热情 提交于 2019-12-05 02:09:07
There seems to be a strange issue with iOS Playgrounds where NSUserDefaults always returns nil instead of the actual value. In an iOS Playground the last line wrongly returns nil . import UIKit let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name") In an OSX Playground the last line correctly returns "This is a test". import Cocoa let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name") Any idea why

Reading NSUserDefaults from helper app in the sandbox

我的未来我决定 提交于 2019-12-05 00:51:36
问题 I found some resources on reading the NSUserDefaults of another application. Objective-C NSUserDefaults caching prevents another app from accurately reading changes NSUserDefaults: Is it possible to get userDefaults from another app? Apparently, it's not possible. However the questions firstly relate to iOS, and secondly the two apps are completely different. I have a LaunchAtLogin helper app. But it does some other tasks too. Therefore, the helper app should run always, but only start the

Shared UserDefaults between app and extension not working correctly

时间秒杀一切 提交于 2019-12-04 22:50:01
So I've been looking around and following all the steps to setup shared UserDefaults correctly but I should be missing something. I have App Groups capability activated on both my app and my extension. Both use the same suite name ( "group.TestSharedPreferences" ) and I write this way: struct Preferences { static let shared = UserDefaults(suiteName: "group.TestSharedPreferences")! } On viewDidLoad : Preferences.shared.set(1, forKey: "INT") And to read: Preferences.shared.integer(forKey: "INT") // Returns 1 in Container App Preferences.shared.integer(forKey: "INT") // Returns 0 in Today

Detecting the initial launch of an app using NSUserDefaults

空扰寡人 提交于 2019-12-04 21:49:08
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 the tutorial above says, it doesn't always work anyway. I keep relaunching from Xcode and it keep

Does NSUserDefaults get erased when an app gets updated?

不羁岁月 提交于 2019-12-04 19:59:45
问题 In my App i am using NSUserDefaults to save some data. I have a doubt regarding this when i update the app in App Store, Will The Data in NSUserDefaults will remain same or it is removed. 回答1: No, it will not be erased on updating 回答2: NSUserDefaults will not be erased during update, but it will be removed when you uninstall an app. 来源: https://stackoverflow.com/questions/8208485/does-nsuserdefaults-get-erased-when-an-app-gets-updated

How to store Array in NSUserDefault in Swift?

天涯浪子 提交于 2019-12-04 19:21:51
So I've been trying for a few hours for a way to store an array to NSUserDefault and print them to the cells but the data is not saving as an array, it basically only saves one value at a time. var emailData = [String]() var passwordData = [String]() @IBAction func addPressed(sender: AnyObject) { let defaults = NSUserDefaults.standardUserDefaults() emailData.append(addEmail.text!) passwordData.append(addPassword.text!) var storedEmail = defaults.objectForKey("emailData") as? [String] ?? [String]() var storedPasswords = defaults.objectForKey("passwordData") as? [String] ?? [String]() // then