Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
//
// DataCenter.h
// 爱鱼奇
//
// Created by imac on 15/9/21.
// Copyright © 2015年 imac. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DataCenter : NSObject
+(instancetype)defaultDtacenter;
//数据存储
-(void)setValue:(id)value forKey:(NSString*)key;
// 获取数据
-(id)valueForKey:(NSString*)key;
@end
+85
View File
@@ -0,0 +1,85 @@
//
// DataCenter.m
// 爱鱼奇
//
// Created by imac on 15/9/21.
// Copyright © 2015年 imac. All rights reserved.
//
#import "DataCenter.h"
@implementation DataCenter
{
NSMutableDictionary *_dict;
}
//获取单例
+(instancetype)defaultDtacenter{
static DataCenter*center=nil;
@synchronized(self){
if (center==nil) {
center=[[self alloc]init];
}
}
return center;
}
//初始化
-(instancetype)init{
if (self=[super init]) {
NSString*filePath=[self getFullFilePathWithName:@"myData.archiver"];
//检测文件是否存在
//保证 _dict指向的对象 和 本地归档文件数据同步
//存在
//读档 /解归档
//成员变量变量是 对象指针 必须要拥有对象的绝对使用权 否则的话 对象可能随时释放
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
_dict=[NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}else{
//不存在
//创建 空的可变字典
//成员变量变量是 对象指针 必须要拥有对象的绝对使用权
_dict=[[NSMutableDictionary alloc]init];
}
}
return self;
}
//根据文件名 获取指定文件名的在沙盒Documents的 全路径
-(NSString*)getFullFilePathWithName:(NSString *)name{
//方法1
// NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
//方法2:获取Documents
//注:NSDocumentDirectory 路径结构 var/mobile/Containers/Data/Application/FC53241A-883C-4770-9117-694E00A41173/Documents/myData.archiver
// NSDocumentationDirectory /var/mobile/Containers/Data/Application/CFE1A228-F736-4018-B100-C8EBCD645630/Library/Documentation/myData.archiver
NSArray*arr=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString*docPath=arr[0];
//检测Documents是否存在
if ([[NSFileManager defaultManager]fileExistsAtPath:docPath]) {
}else{
// NSLog(@"Document不存在");
}
//拼接 文件在 Documents下的路径
return [docPath stringByAppendingPathComponent:name];
}
-(void)setValue:(id)value forKey:(NSString*)key{
//先存入字典
[_dict setObject:value forKey:key];
//立即归档 保证字典 和归档数据同步
BOOL ret=[NSKeyedArchiver archiveRootObject:_dict toFile:[self getFullFilePathWithName:@"myData.archiver"]];
if (!ret) {
// NSLog(@"归档失败");
}
}
//获取数据
-(id)valueForKey:(NSString*)key{
//从字典获取 _dict 和本地归档数据是同步的
return _dict[key];
}
@end
@@ -0,0 +1,19 @@
//
// IfishUncaughtExceptionHandler.h
// Ifish
//
// Created by imac on 17/2/28.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import <Foundation/Foundation.h>
//崩溃日志
@interface IfishUncaughtExceptionHandler : NSObject
+(void)setDefaultHandler;
+(NSUncaughtExceptionHandler *)getHandler;
+(void)TakeException:(NSException *)exception;
@end
@@ -0,0 +1,50 @@
//
// IfishUncaughtExceptionHandler.m
// Ifish
//
// Created by imac on 17/2/28.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishUncaughtExceptionHandler.h"
NSString *applicationDocumentsDirectory(){
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
//崩溃时的回调函数
void UncaughtExceptionHandler(NSException *exception){
NSArray *arr = [exception callStackSymbols];
// 崩溃的原因 可以有崩溃的原因(数组越界,字典nil,调用未知方法...) 崩溃的控制器以及方法
NSString *reason = [exception reason];
NSString *name = [exception name];
NSString * url = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[arr componentsJoinedByString:@"\n"]];
NSString *path = [applicationDocumentsDirectory() stringByAppendingString:@"Exception.txt"];
[url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
@implementation IfishUncaughtExceptionHandler
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
+ (void)setDefaultHandler {
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
}
+ (NSUncaughtExceptionHandler *)getHandler {
return NSGetUncaughtExceptionHandler();
}
+ (void)TakeException:(NSException *)exception {
NSArray * arr = [exception callStackSymbols];
NSString * reason = [exception reason];
NSString * name = [exception name];
NSString * url = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[arr componentsJoinedByString:@"\n"]];
NSString * path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];
[url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
@end
@@ -0,0 +1,52 @@
//
// UserExtendataArchaver.h
// Ifish
//
// Created by imac on 2017/6/9.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RunSunCHControl.h"
#import "RunSunControlName.h"
#import "SongNuo86Name.h"
#import "SongNuo128Name.h"
#import "TwoControlName.h"
#import "ThreeControlName.h"
#import "FourControlName.h"
#import "XuToControlName.h"
@interface UserExtendataArchaver : NSObject
//自定义水族箱名字数据
+(void)archiverDeviceCHInfo:(RunSunCHControl*)ch;
+(RunSunCHControl*)unArchiverDeviceCHInfo:(NSString *)mac;
// 睿芯温控
+(void)saveRuSunTmpname:(RunSunControlName *)nameModel;
+(RunSunControlName *)currentRuSunTemp:(NSString *)macaddress;
//松诺86
+(void)saveSongNuo86Name:(SongNuo86Name *)nameModel;
+(SongNuo86Name *)currentSongNuo86:(NSString *)macaddress;
//松诺128
+(void)saveSongNuo128Name:(SongNuo128Name *)nameModel;
+(SongNuo128Name *)currentSongNuo128:(NSString *)macaddress;
//两空 普通两空0b 闽江0d
+(void)saveTwoControlName:(TwoControlName *)nameModel;
+(TwoControlName *)currentTwoControlName:(NSString *)macaddress;
//三控 所有三控类型
+(void)saveThreeControlName:(ThreeControlName *)nameModel;
+(ThreeControlName *)currentThreeControlName:(NSString *)macaddress;
//四控
+(void)saveFourControlName:(FourControlName *)nameModel;
+(FourControlName *)currentFourControlName:(NSString *)macaddress;
//炫多
+(void)saveXuToControlName:(XuToControlName *)nameModel;
+(XuToControlName *)currentXuToControlName:(NSString *)macaddress;
@end
@@ -0,0 +1,204 @@
//
// UserExtendataArchaver.m
// Ifish
//
// Created by imac on 2017/6/9.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "UserExtendataArchaver.h"
@implementation UserExtendataArchaver
+(void)archiverDeviceCHInfo:(RunSunCHControl*)ch
{
NSString *key = [NSString stringWithFormat:@"Rusun%@",ch.macAd];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:ch toFile:file];
}
+(RunSunCHControl*)unArchiverDeviceCHInfo:(NSString *)mac
{
NSString *key = [NSString stringWithFormat:@"Rusun%@",mac];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
RunSunCHControl *ch = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
return ch;
}
+(void)saveRuSunTmpname:(RunSunControlName *)nameModel{
NSString *key = [NSString stringWithFormat:@"RuSunTmp%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(RunSunControlName *)currentRuSunTemp:(NSString *)macaddress{
NSString *key = [NSString stringWithFormat:@"RuSunTmp%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
RunSunControlName *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[RunSunControlName alloc] init];
controlName.light1 = @"灯1";
controlName.light2 = @"灯2";
controlName.pump = @"水泵";
controlName.JiaRe = @"加热棒";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveSongNuo86Name:(SongNuo86Name *)nameModel{
NSString *key = [NSString stringWithFormat:@"SongNuo%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(SongNuo86Name *)currentSongNuo86:(NSString *)macaddress{
NSString *key = [NSString stringWithFormat:@"SongNuo%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
SongNuo86Name *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[SongNuo86Name alloc] init];
controlName.light1 = @"灯1";
controlName.light2 = @"灯2";
controlName.waterPump = @"水泵";
controlName.airPump = @"氧泵";
controlName.guideng = @"柜灯";
controlName.jiaRe = @"加热棒";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveSongNuo128Name:(SongNuo128Name *)nameModel
{
NSString *key = [NSString stringWithFormat:@"SongNuo%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(SongNuo128Name *)currentSongNuo128:(NSString *)macaddress
{
NSString *key = [NSString stringWithFormat:@"SongNuo%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
SongNuo128Name *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[SongNuo128Name alloc] init];
controlName.light1 = @"灯1";
controlName.light2 = @"灯2";
controlName.waterPump = @"水泵";
controlName.airPump = @"氧泵";
controlName.uVPump = @"UV";
controlName.wave = @"造浪";
controlName.beiYong = @"备用";
controlName.jiaRe = @"加热棒";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveTwoControlName:(TwoControlName *)nameModel
{
NSString *key = [NSString stringWithFormat:@"Two%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(TwoControlName *)currentTwoControlName:(NSString *)macaddress
{
NSString *key = [NSString stringWithFormat:@"Two%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
TwoControlName *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[TwoControlName alloc] init];
controlName.lightName = @"灯";
controlName.pumpName = @"水泵";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveThreeControlName:(ThreeControlName *)nameModel{
NSString *key = [NSString stringWithFormat:@"Three%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(ThreeControlName *)currentThreeControlName:(NSString *)macaddress
{
NSString *key = [NSString stringWithFormat:@"Three%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
ThreeControlName *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[ThreeControlName alloc] init];
controlName.light1Name = @"灯1";
controlName.light2Name = @"灯2";
controlName.pumpName = @"UV/冲浪";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveFourControlName:(FourControlName *)nameModel
{
NSString *key = [NSString stringWithFormat:@"Four%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(FourControlName *)currentFourControlName:(NSString *)macaddress
{
NSString *key = [NSString stringWithFormat:@"Four%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
FourControlName *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[FourControlName alloc] init];
controlName.light1 = @"灯1";
controlName.light2 = @"灯2";
controlName.uvName = @"UV";
controlName.pumpName = @"冲浪";
controlName.macAddress = macaddress;
}
return controlName;
}
+(void)saveXuToControlName:(XuToControlName *)nameModel
{
NSString *key = [NSString stringWithFormat:@"XuTo%@",nameModel.macAddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
[NSKeyedArchiver archiveRootObject:nameModel toFile:file];
}
+(XuToControlName *)currentXuToControlName:(NSString *)macaddress
{
NSString *key = [NSString stringWithFormat:@"XuTo%@",macaddress];
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:key];
XuToControlName *controlName = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
if (!controlName||[controlName isKindOfClass:[NSNull class]]) {
controlName = [[XuToControlName alloc] init];
controlName.airPump = @"气泵";
controlName.light1 = @"灯1";
controlName.light2 = @"灯2";
controlName.huLiDeng = @"护理灯";
controlName.waterPump = @"水泵";
controlName.jiaRe = @"加热棒";
controlName.macAddress = macaddress;
}
return controlName;
}
@end