nsuserdefaults

Detecting the first launch of an app with previous versions

家住魔仙堡 提交于 2019-12-24 11:34:36
问题 I would like to update an app to add a tour on first launch. I would ordinarily handle this with some kind of NSUserDefaults key. However, there are pre-existing existing versions of the app already released. How can I trigger some behavior on first launch of the app, but only for fresh installs and not for the first launch after an update? 回答1: you can check app version via web service. and warn users to update the app. And this case, internet connection required. 回答2: On launch, check for

How to disable a button even when it is not running in the background in swift?

為{幸葍}努か 提交于 2019-12-24 11:11:39
问题 When I say not running in the background, I mean when the user double clicked their home button and swipes up, the button will reenable This is the code in my viewDidLoad if let waitingDate:Date = UserDefaults.standard.value(forKey: "waitingDate") as? Date { let currentDate = Date() if(currentDate.compare(waitingDate) == ComparisonResult.orderedDescending) { getPointsOutlet.isEnabled = true } } This is the code in the @IBAction func getPointsOutlet.isEnabled = false let newDate = Calendar

iOS Swift 3: Share Data from share extension to Host App

断了今生、忘了曾经 提交于 2019-12-24 10:56:06
问题 Hello i have implemented Share extension for my app in which picks images from gallery and send to a particular view. Now the problem is when i'm trying to save array of images(images picked from gallery) func manageImages() { let content = extensionContext!.inputItems[0] as! NSExtensionItem let contentType = kUTTypeImage as String for (index, attachment) in (content.attachments as! [NSItemProvider]).enumerated() { if attachment.hasItemConformingToTypeIdentifier(contentType) { attachment

Dates in UIDatepicker not displaying properly

断了今生、忘了曾经 提交于 2019-12-24 10:44:31
问题 I have UIDatepicker .I have few queries to ask 1.)When i tap on UIButton the dates in datepicker gets retuns to minimum value since i have given maximum and minimum value . In doing that function the date in datepicker appears to be in non highlighted manner ![enter image description here. The link mentioned below shows how the date appears in datepicker http://postimg.org/image/7mlxiq6sz/ - (IBAction)notificationButtonChanged:(UIButton *)control { NSUserDefaults *defaults = [NSUserDefaults

How can I get the UIButton state to be different for each tableView row?

微笑、不失礼 提交于 2019-12-24 08:03:56
问题 In this code I have a selected state and deselected state for my button. When the button has been pressed, it changes to green and when pressed again it changes to red to represent a deselected state. However, all this is in a DetailViewController and when I select a particular row from my tableView then click the button to show green and go back and try a different row, the button shows green on this other row which signifies that I've pressed it(I haven't). I was wondering if there was a

Where does OCUnit store NSUserDefaults?

陌路散爱 提交于 2019-12-24 07:09:47
问题 I read the question Easy way to see saved NSUserDefaults? I found the .plist file for the app, but where's the one for the testing bundle? 回答1: If you use Xcode 4's integration with OCUnit, it injects the test bundle into a running application. NSUserDefaults are therefore saved in the application itself. This is problematic for unit tests: When you run the app manually, your defaults may have been overwritten by your tests. Instead of using [NSUserDefaults standardUserDefaults] directly, use

iOS 8.2 [NSUserDefaults standardUserDefaults] returning nil

泪湿孤枕 提交于 2019-12-24 03:26:09
问题 I am encountering a strange issue in iOS 8.2 where [NSUserDefaults standardUserDefaults] is returning nil on iPhone. This same logic untouched has worked on all previous releases of iOS. I have a universal app which has two different settings.plist one for iPad and the other for iPhone list as follows; Settings.bundle- -Root.plist -Root~iphone.plist When installed on devices the correct settings pane displays and the user can input the appropriate values for the given fields. Though in my app

NSUserDefault and Switches

大城市里の小女人 提交于 2019-12-24 03:16:35
问题 I use NSUserDefaults to save a switch on/off and so far it is good. It remembers the switch position in next session. Now to the thing which I do not understand. I use the same switch (with the same name)in another view, let´s say a flip view which is pushed in from the first view. If I change the switch in the first view it is automatically changed in the flip view. But the other way round, if I change it in the flip view it is not changed in the first view when I go back. Only if I restart

Saving a date in NSUserDefaults (as NSString) not working

时光怂恿深爱的人放手 提交于 2019-12-24 01:51:03
问题 I'm trying to save this date in NSUSerDefaults: 2011-04-14T13:18:25+0000 But I don't want the last bit (+0000), so I chopped it off using this method: NSString *since = [last objectForKey:@"updated_time"]; NSString *cutOff = @"+0000"; NSRange range = [since rangeOfString:cutOff]; self.lastUpdated = [since substringToIndex:range.location]; [[NSUserDefaults standardUserDefaults] setObject:lastUpdated forKey:@"lastUpdated"]; As you can see, it's just a very simple operation that will chop the

Swift: Storing Array of Optionals to NSUserDefaults?

那年仲夏 提交于 2019-12-23 21:18:38
问题 I am trying to save an array of optionals Strings to NSUserDefaults , but unfortunately it doesn't work: var textFieldEntries: [String?] ... func encodeWithCoder(aCoder: NSCoder!) { aCoder.encodeObject(textFieldEntries, forKey: "textFieldEntries") // prints error: Cannot convert value of type '[String?]' // to expected argument type 'AnyObject?' } 回答1: [String?] is a Swift type that cannot be represented as a Foundation type. Normally, Swift Array bridges to NSArray , but an NSArray cannot