nsuserdefaults

Save and Load Data on Today Extensions (iOS 8)

試著忘記壹切 提交于 2019-12-18 05:52:50
问题 Is it possible to save and load data on Today Extension using NSUserDefaults? After closing the Notification Center, the widget behaves like an app which is terminated, so any data results lost. How could I solve this issue? This is my code: NSUserDefaults *defaults; - (void)viewDidLoad { [super viewDidLoad]; defaults = [NSUserDefaults standardUserDefaults]; NSArray *loadStrings = [defaults stringArrayForKey:@"savedStrings"]; if ([loadStrings objectAtIndex:0] != nil) { [display setText:

Store CLLocationCoordinate2D to NSUserDefaults

喜欢而已 提交于 2019-12-18 04:14:11
问题 I am new to iphone development, and i want to store CLLocationCoordinate2D object to NSUserDefaults . I am Trying [defaults setObject:location forKey:@"userLocation"]; But it gives error 'Sending CLLocationCoordinate2D to parameter of incompatible type id' So How to store CLLocationCoordinate2D into NSUserDefaults ? Thanks. 回答1: As pdrcabrod said, "A default object must be a property list, that is, an instance of NSData , NSString , NSNumber , NSDate , NSArray , or NSDictionary ." I use this

Cannot access NSUserDefaults using app groups one to another

六月ゝ 毕业季﹏ 提交于 2019-12-18 04:03:57
问题 I'm working on an app and a widget that the widget needs to get data from app. I've used the following codes to read and write on NSUserDefaults. And also I used $(PRODUCT_BUNDLE_IDENTIFIER).widget for widget and $(PRODUCT_BUNDLE_IDENTIFIER) referring to this post. But widget cannot get the data from app or NSUserDefaults. How can I make it work? func addTask(name: String?) { let key = "keyString" tasks.append(name!) let defaults = NSUserDefaults(suiteName: "group.Mins") defaults?.setObject

Cannot access NSUserDefaults using app groups one to another

自闭症网瘾萝莉.ら 提交于 2019-12-18 04:03:10
问题 I'm working on an app and a widget that the widget needs to get data from app. I've used the following codes to read and write on NSUserDefaults. And also I used $(PRODUCT_BUNDLE_IDENTIFIER).widget for widget and $(PRODUCT_BUNDLE_IDENTIFIER) referring to this post. But widget cannot get the data from app or NSUserDefaults. How can I make it work? func addTask(name: String?) { let key = "keyString" tasks.append(name!) let defaults = NSUserDefaults(suiteName: "group.Mins") defaults?.setObject

Deciding to use Core Data or NSUserDefaults

纵饮孤独 提交于 2019-12-18 03:59:07
问题 I have a feature on my app that allows users to invite their friends (via facebook, or friends in their address book). Most people will have < 5K friends with some people having more (maybe a max of like 10K friends?). I want to keep track of the friends they have invited so they do not re-invite them. To accomplish this I am saving a dict of friends in NSUserDefaults to store this information. I am wondering if NSUserDefaults will suffice for this, or if I need to use Core Data . Also, I am

Is it mandatory to call NSUserDefaults synchronize method?

↘锁芯ラ 提交于 2019-12-18 03:57:20
问题 Please, anyone, help me: Is calling NSUserDefaults 's synchronize() method mandatory?. If I don't call it, what will happen? My application is working fine without it. 回答1: No . Since iOS12, it isn't mandatory anymore. Apple says: This method is unnecessary and shouldn't be used. You can find more information on iOS12 release note: UserDefaults NSUserDefaults has several bug fixes and improvements: Removed synchronization requirements. It's no longer necessary to use synchronize,

Can I use NSUserDefaults with tvOS?

孤街浪徒 提交于 2019-12-18 03:08:04
问题 The App Programming Guide for tvOS briefly states that There is no persistent local storage for apps on Apple TV. This means that every app developed for the new Apple TV must be able to store data in iCloud and retrieve it in a way that provides a great customer experience. Does this mean NSUserDefaults is unavailable? What mechanisms are available for data storage? 回答1: According to an Apple Staff member on the devforums, you can use NSUserDefaults on tvOS for up to 500 kb of data: https:/

NSUserDefaultsDidChangeNotification: What's the name Of the Key, that Changed?

余生长醉 提交于 2019-12-18 02:57:18
问题 This code will call the method "defaultsChanged", when some value in UserDefaults changed NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(defaultsChanged:) name:NSUserDefaultsDidChangeNotification object:nil]; This Code will give me the VALUE that changed - (void)defaultsChanged:(NSNotification *)notification { // Get the user defaults NSUserDefaults *defaults = (NSUserDefaults *)[notification object]; // Do something with it

Check if UserDefault exists - Swift

旧时模样 提交于 2019-12-17 23:32:27
问题 I'm trying to check if the a user default exists, seen below: func userAlreadyExist() -> Bool { var userDefaults : NSUserDefaults = NSUserDefaults.standardUserDefaults() if userDefaults.objectForKey(kUSERID) { return true } return false } However, no mater what it will always return true even when the object doesn't exist yet? Is this the right way for checking existence ? 回答1: Astun has a great answer. See below for the Swift 3 version. func isKeyPresentInUserDefaults(key: String) -> Bool {

iOS NSUserDefaults access before synchronize completion

旧街凉风 提交于 2019-12-17 21:12:27
问题 If I set an NSUserDefault object and try to access it before it has been synchronized , will I be able to access the object I just added? I've tried writing code to test it but I'm unsure of if the synchronization is happening without me knowing it. 回答1: Yes, your application can access the saved preferences before the synchronize happens, if it is saved before the read cycle happens during the same run session of the application. For accessing the information during subsequent app launches