美文网首页
4. 宿主程序存储数据管理器代码

4. 宿主程序存储数据管理器代码

作者: e85a0a8a9ba4 | 来源:发表于2017-05-16 11:10 被阅读23次
/** 1.更新数据 */
- (void)updateDataWithCompletion:(nullable void (^)(NSError *_Nullable error))completion{
    CXCallDirectoryManager *manager = [CXCallDirectoryManager sharedInstance];
    [manager reloadExtensionWithIdentifier:IdentifierExtension completionHandler:^(NSError * _Nullable error) {
        NSLog(@"%s %@", __FUNCTION__, error);
        completion(error);
    }];
}

/** 2.获取权限 */
- (void)getEnabledStatusWithCompletionHandler:(void (^)(CXCallDirectoryEnabledStatus enabledStatus, NSError *_Nullable error))completion{
    CXCallDirectoryManager *manager = [CXCallDirectoryManager sharedInstance];
    [manager getEnabledStatusForExtensionWithIdentifier:IdentifierExtension completionHandler:^(CXCallDirectoryEnabledStatus enabledStatus, NSError * _Nullable error) {
        completion(enabledStatus, error);
    }];
}

/** 3.保存通讯录来电信息 */
- (void)saveDataWithCompletion:(void(^)(BOOL success))completion{
    NSString *filePathIdentification = [self readPathIdentification];
    //    [[NSFileManager defaultManager] removeItemAtPath:filePathIdentification error:nil];
    if (self.arrayCall.count > 0) {
        BOOL success = [self.arrayCall writeToFile:filePathIdentification atomically:YES];
        if (success) {
            completion(YES);
        }else {
            completion(NO);
        }
    }else{
        completion(YES);
    }
}
- (void)saveKHDataWithCompletion:(void(^)(BOOL success))completion{
    NSString *filePathIdentification = [self readKeHuPlistPath];
    //    [[NSFileManager defaultManager] removeItemAtPath:filePathIdentification error:nil];
    if (self.khCall.count > 0) {
        BOOL success = [self.khCall writeToFile:filePathIdentification atomically:YES];
        if (success) {
            completion(YES);
        }else {
            completion(NO);
        }
    }else{
        completion(YES);
    }
}
- (void)saveLXRDataWithCompletion:(void(^)(BOOL success))completion{
    NSString *filePathIdentification = [self readLXRPlistPath];
    //    [[NSFileManager defaultManager] removeItemAtPath:filePathIdentification error:nil];
    if (self.lxrCall.count > 0) {
        BOOL success = [self.lxrCall writeToFile:filePathIdentification atomically:YES];
        if (success) {
            completion(YES);
        }else {
            completion(NO);
        }
    }else{
        completion(YES);
    }
}

/** 4.读取来电信息 */
-(NSArray<NSDictionary *> *)readData
{
    NSString *filePathIdentification = [self readPathIdentification];
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePathIdentification];
    NSDictionary *dic = [arr firstObject];
    NSArray *dataArr = [dic allKeys];
    return [self arraySort:dataArr ASC:YES];
}
-(NSArray<NSDictionary *> *)readKHData
{
    NSString *filePathIdentification = [self readKeHuPlistPath];
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePathIdentification];
    NSDictionary *dic = [arr firstObject];
    NSArray *dataArr = [dic allKeys];
    return [self arraySort:dataArr ASC:YES];
}
-(NSArray<NSDictionary *> *)readLXRData
{
    NSString *filePathIdentification = [self readLXRPlistPath];
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePathIdentification];
    NSDictionary *dic = [arr firstObject];
    NSArray *dataArr = [dic allKeys];
    return [self arraySort:dataArr ASC:YES];
}

/** 1.获取通讯录扩展文件位置 */
- (NSString *)readPathIdentification{
    NSURL *fileUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@""];
    NSString *filePath = [fileUrl.absoluteString substringFromIndex:(@"file://".length)];
    NSString *filePathIdentification = [filePath stringByAppendingString:@""];
    return filePathIdentification;
    
}
//获取客户Plist路径
-(NSString *)readKeHuPlistPath{
    NSURL *fileUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@""];
    NSString *filePath = [fileUrl.absoluteString substringFromIndex:(@"file://".length)];
    NSString *filePathIdentification = [filePath stringByAppendingString:@""];
    
    return filePathIdentification;
}
//获取客户Plist路径
-(NSString *)readLXRPlistPath{
    NSURL *fileUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@""];
    NSString *filePath = [fileUrl.absoluteString substringFromIndex:(@"file://".length)];
    NSString *filePathIdentification = [filePath stringByAppendingString:@""];
    
    return filePathIdentification;
}

/** 2.数组排序 */
- (NSArray<NSDictionary *> *)arraySort:(NSArray<NSDictionary *> *)array ASC:(BOOL)ASC
{
    
    if (array == nil || [array count] == 0) {
        return nil;
    }
    
    return [array sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
        if(ASC){
            if([obj1 integerValue] > [obj2 integerValue]) {
                return(NSComparisonResult)NSOrderedDescending;
            }
            if([obj1 integerValue] < [obj2 integerValue]) {
                return(NSComparisonResult)NSOrderedAscending;
            }
        }else{
            if([obj1 integerValue] < [obj2 integerValue]) {
                return(NSComparisonResult)NSOrderedDescending;
            }
            if([obj1 integerValue] > [obj2 integerValue]) {
                return(NSComparisonResult)NSOrderedAscending;
            }
        }
        return(NSComparisonResult)NSOrderedSame;
    }];
}

- (NSMutableArray<NSDictionary *> *)arrayCall
{
    if (!_arrayCall) {
        if ([self readData].count > 0) {
            _arrayCall = [self readData].mutableCopy;
        }else {
            _arrayCall = @[].mutableCopy;
        }
    }
    return _arrayCall;
}
-(NSMutableArray<NSDictionary *> *)khCall{
    if (!_khCall) {
        if ([self readKHData].count > 0) {
            _khCall = [self readKHData].mutableCopy;
        }else {
            _khCall = @[].mutableCopy;
        }
    }
    return _khCall;
}
-(NSMutableArray<NSDictionary *> *)lxrCall{
    if (!_lxrCall) {
        if ([self readLXRData].count > 0) {
            _lxrCall = [self readLXRData].mutableCopy;
        }else{
            _lxrCall = @[].mutableCopy;
        }
    }
    return _lxrCall;
}

相关文章

  • 4. 宿主程序存储数据管理器代码

  • 第23章、存储程序和视图

    本章讨论存储的程序和视图,这些数据库对象是根据存储在服务器上供以后执行的SQL代码定义的数据库对象。 存储的程序包...

  • 图解简单C程序的运行时结构

    程序在内存中的存储分为三个区域,分别是动态数据区、静态数据区和代码区。函数存储在代码区,全局变量以及静态变量存储在...

  • rabbitmq 学习

    组件 ConnectionFactory(连接管理器):应用程序与Rabbit之间建立连接的管理器,程序代码中使用...

  • CentOS程序包管理

    通过程序包管理器安装软件 Linux上通过使用程序包管理器安装软件 程序包管理器 :将源代码 编译后目标二进制格式...

  • python-函数-变量

    变量 程序中临时存储数据的容器[程序运行过程中,可以存储数据,一旦程序停止运行,程序中 的变量中存储...

  • [Windows] 多标签文件管理XYplorer20.60绿色

    XYplorer 是一个便携式的文件管理器。它不需要任何安装, 所有的配置数据存储在应用程序数据文件夹中,运行它不...

  • 存储器知识

    存储器是用来存储程序代码和数据的部件,有了存储器计算机才具有记忆功能。 1.存储器种类 存储器按存储介质特性主要...

  • 一个简单C程序的汇编程序执行分析

    1.冯诺依曼体系结构——存储程序式计算机 冯诺依曼体系结构核心是存储程序,将数据和代码都存储在存取器中,都是二进制...

  • 在内存剖析对象

    对象在内存中的存储 栈、堆、BSS、数据段、代码段是什么?栈(stack):又称作堆栈,用来存储程序的局部变量(但...

网友评论

      本文标题:4. 宿主程序存储数据管理器代码

      本文链接:https://www.haomeiwen.com/subject/lgflxxtx.html