技能卡列表
编辑技能卡 新增技能卡接口调试 技能卡列表cell 技能卡列表UI优化,删除技能卡 新增技能卡时保存按钮不可点击 个人资料卡增加技能卡 声音秀技能卡 技能卡声音录制、上传,重新录制 技能卡声音秀展示 技能卡多选 技能卡编辑、多选优化 技能卡声音秀删除、重新录制
This commit is contained in:
89
xplan-ios/Base/Tool/File/CommonFileUtils.h
Normal file
89
xplan-ios/Base/Tool/File/CommonFileUtils.h
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// CommonFileUtils.h
|
||||
// Commons
|
||||
//
|
||||
// Created by 小城 on 14-6-5.
|
||||
// Copyright (c) 2014年 YY Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface CommonFileUtils : NSObject
|
||||
|
||||
/**Some FilePaths
|
||||
*/
|
||||
+ (NSString *)documentsDirectory;
|
||||
+ (NSString *)cachesDirectory;
|
||||
|
||||
/**
|
||||
* File Operation
|
||||
*/
|
||||
|
||||
/**
|
||||
* 创建文件所在的目录
|
||||
*
|
||||
* @param path 文件的绝对路径
|
||||
*
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
+ (BOOL)createDirForPath:(NSString *)path;
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
*
|
||||
* @param dirPath 目录绝对路径
|
||||
*
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
+ (BOOL)createDirWithDirPath:(NSString *)dirPath;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param path 文件所在的绝对路径
|
||||
*
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
+ (BOOL)deleteFileWithFullPath:(NSString *)path;
|
||||
|
||||
/**
|
||||
* 指定路径的文件是否存在
|
||||
*
|
||||
* @param filePath 文件的绝对路径
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
+ (BOOL)isFileExists:(NSString *)filePath;
|
||||
|
||||
/**
|
||||
* 在文件的末尾追加文本内容
|
||||
*
|
||||
* @param content 文本内容
|
||||
* @param filePath 文件绝对路径,比如保证该文件是存在的,返回会返回NO
|
||||
*
|
||||
* @return 是否追加成功
|
||||
*/
|
||||
+ (BOOL)appendContent:(NSString *)content toFilePath:(NSString *)filePath;
|
||||
|
||||
|
||||
/**FileUtils In UserDefault
|
||||
*/
|
||||
+ (BOOL)writeObject:(id)object toUserDefaultWithKey:(NSString*)key;
|
||||
+ (id)readObjectFromUserDefaultWithKey:(NSString*)key;
|
||||
+ (BOOL)deleteObjectFromUserDefaultWithKey:(NSString*)key;
|
||||
|
||||
/**FileUtils In CachesPath
|
||||
*/
|
||||
+ (void)writeObject:(id)object toCachesPath:(NSString*)path;
|
||||
+ (id)readObjectFromCachesPath:(NSString*)path;
|
||||
+ (BOOL)deleteFileFromCachesPath:(NSString *)path;
|
||||
|
||||
/**FileUtils In DocumentPath
|
||||
*/
|
||||
+ (void)writeObject:(id)object toDocumentPath:(NSString *)path;
|
||||
+ (id)readObjectFromDocumentPath:(NSString *)path;
|
||||
+ (BOOL)deleteFileFromDocumentPath:(NSString *)path;
|
||||
|
||||
+ (BOOL)copyItem:(NSString *)destination toPath:(NSString *)toPath;
|
||||
|
||||
@end
|
273
xplan-ios/Base/Tool/File/CommonFileUtils.m
Normal file
273
xplan-ios/Base/Tool/File/CommonFileUtils.m
Normal file
@@ -0,0 +1,273 @@
|
||||
//
|
||||
// CommonFileUtils.m
|
||||
// Commons
|
||||
//
|
||||
// Created by 小城 on 14-6-5.
|
||||
// Copyright (c) 2014年 YY Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "CommonFileUtils.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation CommonFileUtils
|
||||
|
||||
+ (NSString *)documentsDirectory
|
||||
{
|
||||
static NSString *docsDir = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
||||
});
|
||||
return docsDir;
|
||||
}
|
||||
|
||||
+ (NSString *)cachesDirectory
|
||||
{
|
||||
static NSString *cachesDir = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
||||
});
|
||||
return cachesDir;
|
||||
}
|
||||
|
||||
+ (BOOL)createDirForPath:(NSString *)path
|
||||
{
|
||||
return [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
|
||||
+ (BOOL)createDirWithDirPath:(NSString *)dirPath
|
||||
{
|
||||
return [[NSFileManager defaultManager] createDirectoryAtPath:dirPath
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:nil];
|
||||
}
|
||||
|
||||
+ (BOOL)deleteFileWithFullPath:(NSString *)fullPath
|
||||
{
|
||||
BOOL deleteSucc = NO;
|
||||
if ([[NSFileManager defaultManager] isDeletableFileAtPath:fullPath]) {
|
||||
deleteSucc = [[NSFileManager defaultManager] removeItemAtPath:fullPath error:NULL];
|
||||
}
|
||||
|
||||
return deleteSucc;
|
||||
}
|
||||
|
||||
|
||||
/**UserDefault
|
||||
*/
|
||||
+ (BOOL)writeObject:(id)object toUserDefaultWithKey:(NSString*)key
|
||||
{
|
||||
if (object == nil || key == nil) return NO;
|
||||
|
||||
NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:object];
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setObject:myEncodedObject forKey:key];
|
||||
return [defaults synchronize];
|
||||
}
|
||||
|
||||
+ (id)readObjectFromUserDefaultWithKey:(NSString*)key
|
||||
{
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSData *myEncodedObject = [defaults objectForKey:key];
|
||||
|
||||
if (myEncodedObject == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@try {
|
||||
return [NSKeyedUnarchiver unarchiveObjectWithData: myEncodedObject];
|
||||
}
|
||||
@catch (NSException *e){
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)deleteObjectFromUserDefaultWithKey:(NSString*)key
|
||||
{
|
||||
if (!key) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults removeObjectForKey:key];
|
||||
return [defaults synchronize];
|
||||
}
|
||||
|
||||
+ (BOOL)isFileExists:(NSString *)filePath
|
||||
{
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:filePath];
|
||||
}
|
||||
|
||||
+ (BOOL)appendContent:(NSString *)content toFilePath:(NSString *)filePath
|
||||
{
|
||||
if (![CommonFileUtils isFileExists:filePath]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL appendSucc = YES;
|
||||
|
||||
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
|
||||
if (!fileHandle) {
|
||||
appendSucc = NO;
|
||||
} else {
|
||||
[fileHandle seekToEndOfFile];
|
||||
[fileHandle writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[fileHandle closeFile];
|
||||
}
|
||||
|
||||
return appendSucc;
|
||||
}
|
||||
|
||||
|
||||
/**CachesPath
|
||||
*/
|
||||
+ (void)writeObject:(id)object toCachesPath:(NSString*)path
|
||||
{
|
||||
if (object == nil || [path length] == 0)
|
||||
return;
|
||||
|
||||
NSString *fullPath = [[CommonFileUtils cachesDirectory] stringByAppendingPathComponent:path];
|
||||
[CommonFileUtils _writeObject:object toPath:fullPath];
|
||||
}
|
||||
|
||||
+ (id)readObjectFromCachesPath:(NSString*)path
|
||||
{
|
||||
if ([path length] == 0)
|
||||
return nil;
|
||||
|
||||
NSString *fullPath = [[CommonFileUtils cachesDirectory] stringByAppendingPathComponent:path];
|
||||
return [CommonFileUtils _readObjectFromPath:fullPath];
|
||||
}
|
||||
|
||||
+ (BOOL)deleteFileFromCachesPath:(NSString *)path
|
||||
{
|
||||
NSString *fullPath = [[CommonFileUtils cachesDirectory] stringByAppendingPathComponent:path];
|
||||
return [CommonFileUtils deleteFileWithFullPath:fullPath];
|
||||
}
|
||||
|
||||
/**DocumentPath
|
||||
*/
|
||||
+ (void)writeObject:(id)object toDocumentPath:(NSString *)path
|
||||
{
|
||||
if (object == nil || [path length] == 0)
|
||||
return;
|
||||
|
||||
NSString *fullPath = [[CommonFileUtils documentsDirectory] stringByAppendingPathComponent:path];
|
||||
[CommonFileUtils _writeObject:object toPath:fullPath];
|
||||
|
||||
}
|
||||
|
||||
+ (id)readObjectFromDocumentPath:(NSString *)path
|
||||
{
|
||||
if ([path length] == 0)
|
||||
return nil;
|
||||
|
||||
NSString *fullPath = [[CommonFileUtils documentsDirectory] stringByAppendingPathComponent:path];
|
||||
return [CommonFileUtils _readObjectFromPath:fullPath];
|
||||
}
|
||||
|
||||
+ (BOOL)deleteFileFromDocumentPath:(NSString *)path
|
||||
{
|
||||
NSString *fullPath = [[CommonFileUtils documentsDirectory] stringByAppendingPathComponent:path];
|
||||
return [CommonFileUtils deleteFileWithFullPath:fullPath];
|
||||
}
|
||||
|
||||
+ (BOOL)copyItem:(NSString *)destination toPath:(NSString *)toPath
|
||||
{
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] copyItemAtPath:destination toPath:toPath error:&error];
|
||||
return error != nil;
|
||||
}
|
||||
|
||||
#pragma mark - private
|
||||
static id getSemaphore(NSString *key)
|
||||
{
|
||||
static NSMutableDictionary *dict = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
dict = [[NSMutableDictionary alloc] initWithCapacity:10];
|
||||
});
|
||||
|
||||
id obj = [dict objectForKey:key];
|
||||
if (!obj)
|
||||
{
|
||||
obj = [[NSObject alloc] init];
|
||||
[dict setObject:obj forKey:key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
static dispatch_queue_t getFileQueue()
|
||||
{
|
||||
static dispatch_queue_t queue = NULL;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
queue = dispatch_queue_create("FileQueue", NULL);
|
||||
});
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
+ (void)_writeObject:(id)obj toPath:(NSString *)fullPath
|
||||
{
|
||||
if (obj == nil || [fullPath length] == 0)
|
||||
return;
|
||||
|
||||
id newObj = obj;
|
||||
if ([obj isKindOfClass:[NSArray class]] || [obj isKindOfClass:[NSDictionary class]])
|
||||
{
|
||||
//集合类型为了避免出现写的同时另一个线程在操作同一个集合可能导致崩溃,这里在主线程生成一个新的集合
|
||||
if ([obj isKindOfClass:[NSMutableArray class]])
|
||||
newObj = [NSMutableArray arrayWithArray:obj];
|
||||
else if ([obj isKindOfClass:[NSArray class]])
|
||||
newObj = [NSArray arrayWithArray:obj];
|
||||
else if ([obj isKindOfClass:[NSMutableDictionary class]])
|
||||
newObj = [NSMutableDictionary dictionaryWithDictionary:obj];
|
||||
else
|
||||
newObj = [NSDictionary dictionaryWithDictionary:obj];
|
||||
}
|
||||
|
||||
id sema = getSemaphore(fullPath);
|
||||
|
||||
//在queue中操作
|
||||
dispatch_async(getFileQueue(), ^{
|
||||
@synchronized(sema)
|
||||
{
|
||||
//必须先创建目录,否则archiveRootObject操作在没有目录的情况下会失败!
|
||||
if ([CommonFileUtils createDirForPath:fullPath])
|
||||
{
|
||||
[NSKeyedArchiver archiveRootObject:newObj toFile:fullPath];
|
||||
}
|
||||
// else
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+ (id)_readObjectFromPath:(NSString *)fullPath
|
||||
{
|
||||
id sema = getSemaphore(fullPath);
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath])
|
||||
{
|
||||
@try
|
||||
{
|
||||
@synchronized(sema)
|
||||
{
|
||||
return [NSKeyedUnarchiver unarchiveObjectWithFile:fullPath];
|
||||
}
|
||||
}
|
||||
@catch (NSException *e)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
28
xplan-ios/Base/Tool/File/UploadFile.h
Normal file
28
xplan-ios/Base/Tool/File/UploadFile.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// UploadFile.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by GreenLand on 2022/2/23.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface UploadFile : NSObject
|
||||
|
||||
/// 上传一个文件
|
||||
/// @param filePath 文件地址
|
||||
/// @param fileName 文件的名字
|
||||
/// @param token token
|
||||
/// @param success 成功
|
||||
/// @param failure 失败
|
||||
+ (void)uploadFile:(NSString *)filePath
|
||||
named:(NSString *)fileName
|
||||
token:(NSString *)token
|
||||
success:(void (^)(NSString *key, NSDictionary *resp))success
|
||||
failure:(void (^)(NSNumber *resCode, NSString *message))failure;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
37
xplan-ios/Base/Tool/File/UploadFile.m
Normal file
37
xplan-ios/Base/Tool/File/UploadFile.m
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// UploadFile.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by GreenLand on 2022/2/23.
|
||||
//
|
||||
|
||||
#import "UploadFile.h"
|
||||
#import <Qiniu/QiniuSDK.h>
|
||||
|
||||
@implementation UploadFile
|
||||
|
||||
/// 上传一个文件
|
||||
/// @param filePath 文件地址
|
||||
/// @param fileName 文件的名字
|
||||
/// @param token token
|
||||
/// @param success 成功
|
||||
/// @param failure 失败
|
||||
+ (void)uploadFile:(NSString *)filePath
|
||||
named:(NSString *)fileName
|
||||
token:(NSString *)token
|
||||
success:(void (^)(NSString *key, NSDictionary *resp))success
|
||||
failure:(void (^)(NSNumber *resCode, NSString *message))failure {
|
||||
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
|
||||
builder.zone = [QNFixedZone zone2];
|
||||
}];
|
||||
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:config];
|
||||
[upManager putFile:filePath key:fileName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
|
||||
if (resp) {
|
||||
success(key,resp);
|
||||
}else{
|
||||
failure(@(info.statusCode),info.error.localizedDescription);
|
||||
}
|
||||
} option:nil];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user