IOS7 App Development Essentials(3)NSUserDefaults
In Android world, we have SharedPreferences, in iOS world, we should use NSUserDetails.
The NSUserDefaults class provides a interface for interacting with the defaults system.
Applications record such preferences by assigning values to a set of parameters in a user’s defaults databases. NSUserDefaults caches the information to avoid having to open the user’s defaults database.
It will support these classes
NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary
It support NSDictionary.
Here is How I use NSUserDefaults
Define the interface
@interface SLUserDefaults : NSObject + (NSDictionary *)getBeaconDataDictionary; + (void)setBeaconDataDictionary:(NSDictionary *)beacons;
+(void)setBeaconRangingOutside:(NSString *)identifier; +(NSString *)getBeaconRangingOutside;
+ (void)setBeaconRangingBeacons:(NSSet *)beacons; + (NSSet *)getBeaconRangingBeacons;
+ (BOOL)isBeaconRangeRunning; + (void)setBeaconRangeRunning:(BOOL) status;
Here is the implementation
#import “SLUserDefaults.h"staticNSString *const DEVICE_REGISTERED_KEY = @“SL_isRegistered"; staticNSString *const IS_STARTED_KEY = @“SL_isStarted";
@implementation LPUserDefaults
+ (NSDictionary *)getBeaconDataDictionary{ @synchronized(self){ if([[NSUserDefaultsstandardUserDefaults] objectForKey:BEACON_DATA_DIC]){ return [NSKeyedUnarchiverunarchiveObjectWithData:[[NSUserDefaultsstandardUserDefaults] objectForKey:BEACON_DATA_DIC]]; }else{ return [[NSDictionaryalloc] init]; } } } + (void)setBeaconDataDictionary:(NSDictionary *)beacons { @synchronized(self){ if(beacons != nil && [beacons count] > 0){ NSData *encodedObjects = [NSKeyedArchiverarchivedDataWithRootObject:beacons]; [[NSUserDefaultsstandardUserDefaults] setObject:encodedObjects forKey:BEACON_DATA_DIC]; } } }
+ (void)setBeaconDataDictionary:(NSDictionary *)beacons { @synchronized(self){ if(beacons != nil && [beacons count] > 0){ NSData *encodedObjects = [NSKeyedArchiverarchivedDataWithRootObject:beacons]; [[NSUserDefaultsstandardUserDefaults] setObject:encodedObjects forKey:BEACON_DATA_DIC]; } } } +(void)setBeaconRangingOutside:(NSString *)identifier{ @synchronized(self){ [[NSUserDefaultsstandardUserDefaults] setValue:identifier forKey:BEACON_RANGING_OUTSIDE]; } }
+ (void)setBeaconMonitoringBeacons:(NSSet *)beacons { @synchronized(self){ if(beacons != nil && [beacons count] > 0){ NSData *encodedObjects = [NSKeyedArchiverarchivedDataWithRootObject:beacons]; [[NSUserDefaultsstandardUserDefaults] setObject:encodedObjects forKey:BEACON_MONITORING_BEACONS]; } } } + (NSSet *)getBeaconMonitoringBeacons{ @synchronized(self){ if([[NSUserDefaultsstandardUserDefaults] objectForKey:BEACON_MONITORING_BEACONS]){ return [NSKeyedUnarchiverunarchiveObjectWithData:[[NSUserDefaultsstandardUserDefaults] objectForKey:BEACON_MONITORING_BEACONS]]; }else{ return [[NSSetalloc] init ]; } } }
+ (BOOL)isRegistered { @synchronized(self) { return [[NSUserDefaultsstandardUserDefaults] boolForKey:DEVICE_REGISTERED_KEY]; } } + (void)setRegistered { @synchronized(self) { [[NSUserDefaultsstandardUserDefaults] setBool:YESforKey:DEVICE_REGISTERED_KEY]; } }
References:
http://sillycat.iteye.com/blog/1841920
Store Object
http://stackoverflow.com/questions/2315948/how-to-store-custom-objects-in-nsuserdefaults
- 浏览: 2551315 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
ionic UI(5)UI and Backend
2016-12-02 03:22 597ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 903Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 986Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 990IOS7 App Development Essentia ... -
IPhone and Location(2)Documents Region Monitoring and Region Sample
2013-10-18 05:10 1737IPhone and Location(2)Documents ... -
IPhone and Location(1)Documents User Location
2013-10-18 03:50 1311IPhone and Location(1)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 932Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 1002Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 938Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 1019Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 971Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1116Learn Object C(1) Learn Objec ... -
APNS(4)Recall the Process and Learn Java APNS
2013-04-18 02:48 3476APNS(4)Recall the Process and L ... -
Build the iOS Things with J2Objc
2013-04-12 03:25 2468Build the iOS Things with J2Obj ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1721APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1546APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1325Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1097Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1336MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1930Android Talker(1)MAC Environmen ...
相关推荐
iOS 10 App Development Essentials: Learn to Develop iOS 10 Apps with Xcode 8 and Swift 3 Author: Neil Smyth Length: 816 pages Edition: 1 Language: English Publisher: CreateSpace Independent Publishing...
iOS 11 App Development Essentials Learn to Develop iOS 11 Apps with Xcode 9 and Swift 4 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
3. 苹果开发者计划的加入:本书籍指导读者如何加入苹果开发者计划,以便更好地进行iOS应用的开发和测试。其中包括下载Xcode 9、加入开发者计划的时机和步骤,以及如何使用开发者ID进行开发和分发。 4. Xcode 9的...
iOS 11 App Development Essentials Learn to Develop iOS 11 Apps with Xcode 9 and Swift 4 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
《iOS 8应用开发基础》源码解析 本资源包含了使用Xcode 6.3(Swift 1.2)编写的iOS 8应用程序开发的基础源码。这些源代码旨在帮助开发者深入理解iOS 8应用开发的基本概念和技术,通过实际操作来学习Swift语言以及...
iOS 10 App Development Essentials 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
3. 创建基础iOS 7应用的步骤和遇到常见问题的处理方法。 4. 测试和适配应用在不同设备和iOS版本上的显示效果。 5. 监控应用性能,确保良好的用户体验。 6. 理解iOS 7的系统架构以及常用SDK框架的作用和使用方法。 7....
iOS 9 App Development Essentials 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系...
本书《iOS 11 App Development Essentials》旨在帮助读者掌握开发 iOS 11 应用所需的基本技能。它覆盖了从安装开发环境到构建应用的全过程,并深入介绍了 Swift 4 编程语言的基础知识。对于新接触 iOS 开发的人来说...
3. 安装Xcode9和iOS 11 SDK 书中强调了区分Mac电脑是基于Intel还是PowerPC架构的重要性,因为这对于安装Xcode和iOS SDK有着直接的影响。书中还介绍了如何安装Xcode9,如何在Xcode偏好设置中添加Apple ID,以及如何...
本书概述了iPhone硬件和iOS 4的体系结构。提供了Objective-C编程的简介,然后深入研究了iPhone应用程序和用户界面的设计。
介绍如何使用Xcode和Swift构建适用于iOS 8的应用程序。
本书旨在教授使用 iOS 16 SDK、UIKit、Xcode 14 和 Swift 编程语言创建 iOS 应用程序所需的技能。 本书从基础开始,概述了设置 iOS 开发环境所需的步骤。接下来,介绍了 iOS 16 的架构和 Swift 5.7 中的编程,然后...
Title: iOS 8 App Development Essentials Author: Neil Smyth Length: 824 pages Edition: 1 Language: English Publisher: CreateSpace Independent Publishing Platform Publication Date: 2014-12-16 ISBN-10: ...
### iPad iOS 4 App开发要点-Xcode 4版 #### 引言 随着移动设备的普及,特别是苹果公司的iPad发布后,iOS平台的应用程序开发变得越来越重要。本篇内容将聚焦于iPad上运行的iOS 4应用程序开发的核心知识点,特别强调...
iOS 9 App Development Essentials is latest edition of this popular book series and has now been fully updated for the iOS 9 SDK, Xcode 7 and the Swift 2 programming language. Beginning with the ...
总结来说,《iOS 9 Game Development Essentials》这本书覆盖了从基础的 Swift 编程语言到高级的游戏开发技术,适合想要入门 iOS 游戏开发的读者。通过本书的学习,你将能够掌握使用 Swift 和 SpriteKit/SceneKit ...
使用Eclipse IDE和Android 4.2 SDK的Android应用程序开发简介。 本书假定您具有Java编程经验。