nsuserdefaults

Swift: self.init (coder : aDecoder) is crashing app with EXC_BAD_ACCESS

徘徊边缘 提交于 2020-01-17 06:46:35
问题 Error is crashing app when using NSCoder and NSKeyArchiver. I had made a recent post around NSCoder but since then I've changed my code around and got a new error and decided a new post is best. The app is a blog reader, reading from a MYSQL database using PHP to fill a table view with custom objects in Swift using JSON. I've been trying to save mainArray so that when the user moves cells across sections (each section has an array) it can save where the user left it. Blog.swift: Handles the

Handle local notification tap Xamarin Forms iOS

懵懂的女人 提交于 2020-01-17 01:39:06
问题 I have created an application on Xamarin Forms in which I am scheduling local notifications in PCL through a Plugin named Plugin.Notifications. But I wanted to know whether the user enters into the app through notification or not. I tried to check whether the UIApplication.LaunchOptionsLocalNotificationKey is present in the launch 'options' dictionary or not, but the launch options dictionary is always null. Then I tried to handle it through the ReceivedLocalNotification delegate method, and

Sharing data between app extension and conainer app

折月煮酒 提交于 2020-01-16 00:42:11
问题 I'm trying to share data between an app extension and my container app. I setup an app group in the container app and referenced it my app extension. When my app extension is accessed, I save an object to NSUserDefaults //in the app extension -(void)viewDidLoad { NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.mygroup.com"]; [defaults setObject:[NSDate date] forKey:@"Date"]; [defaults synchronize]; } and in the container app - when it is launched I setup an

Save last datePicker selection

徘徊边缘 提交于 2020-01-15 03:39:28
问题 I have a project with an UIDatePicker . I want that if I change my UIDatePicker value, for example at 9:23, when I restart my app value is still 9:23 and not the default value. How can I do that? Here is my code: @IBOutlet var myDatePicker: UIDatePicker! var datePicker = /* Get Your Date Picker from somewhere */ // Store value using User Defaults let currentDate = datePicker.date NSUserDefaults.standardUserDefaults().setObject(currentDate, forKey: "Current-Date") // Retrieve Value using User

how to save plist to NSUserDefaults

青春壹個敷衍的年華 提交于 2020-01-15 01:21:19
问题 I am trying to save a .plist I have created into my NSUserDefaults so that I can save the data that I am putting into it, so if the app is stopped (removed from multitasking bar) I do not loose the values. I have been pointed to this tutorial here In it is has this sample code. -(void)saveToUserDefaults:(NSString*)myString { NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; if (standardUserDefaults) { [standardUserDefaults setObject:myString forKey:@"Prefs"];

UserDefaults is not saved with Swift 3

最后都变了- 提交于 2020-01-14 07:03:09
问题 I'm trying to use the UserDefaults to persistently save a boolean value. This is my code : public static var isOffline = UserDefaults.standard.bool(forKey: "isOffline") { didSet { print("Saving isOffline flag which is now \(isOffline)") UserDefaults.standard.set(isOffline, forKey: "isOffline") UserDefaults.standard.synchronize() } } Why doesn't work? What is the problem in this code? EDIT: The problem is that when I try to retrieve "isOffline" key from UserDefaults I always get a false . EDIT

NSUserDefaults standardUserDefaults setObject: forKey: not working for Multivalue preference

女生的网名这么多〃 提交于 2020-01-14 03:27:10
问题 I am trying to do following task [[NSUserDefaults standardUserDefaults] setObject:@"Dry" forKey:@"vesselType_preference"]; [[NSUserDefaults standardUserDefaults] synchronize]; where my "vesselType_preference" is multivalue attribute, but it is not getting effected. Please help this is working for other type of attribute but not working for multivalue type. Thanks 回答1: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (![defaults objectForKey:@"vesselType_preference"]) {

How to save a color in NSUserDefaults in swift?

时光怂恿深爱的人放手 提交于 2020-01-12 05:42:05
问题 I have a litle problem with saving a color in NSUserDefaults . In objective-c is easy : -(NSColor *)colorForKey:(NSString *)key{ NSData *data; NSColor *color; data = [[NSUserDefaults standardUserDefaults] objectForKey:key]; color= [NSUnarchiver unarchiveObjectWithData:data]; if( ! [color isKindOfClass:[NSColor class]] ){ color = nil; } return color; } -(void)setColor:(NSColor *)color forKey:(NSString *)key{ NSData *data = [NSArchiver archivedDataWithRootObject:color]; [[NSUserDefaults

NSUserDefaults not saving

拟墨画扇 提交于 2020-01-11 05:07:32
问题 I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called) if (![defaults objectForKey:@"obj"]) { difficultyLabel.text = @"Difficulty: Easy"; [defaults setObject:@"Easy" forKey:@"obj"]; } else { difficultyLabel.text = [NSString stringWithFormat:@"Difficulty: %@", [defaults objectForKey:@"diff"]]; } and then when you click on the SKLabelNode to change the difficulty and this code is being called if ([label

Determine if user has enabled application's Safari content blocker extension

眉间皱痕 提交于 2020-01-09 19:44:28
问题 I'm working on a Safari Content Blocking extension. I intend to show setup instructions if the extension is disabled and to show settings if it is conversely enabled. How can I determine if the extension is enabled by the user? I've seen this method to detect if a custom keyboard is activated but there's no key on NSUserDefaults that relates to Safari Content Blockers. 回答1: As of iOS 10, there is a new method in SFContentBlockerManager to support this: getStateOfContentBlocker(withIdentifier