Commit 14e5c624f67c21e7ce1c3a8de563460419252951
1 parent
bd508a87
提交更爱
Showing
14 changed files
with
717 additions
and
267 deletions
CNLiveICloudPicker.podspec
| @@ -96,7 +96,7 @@ Pod::Spec.new do |s| | @@ -96,7 +96,7 @@ Pod::Spec.new do |s| | ||
| 96 | # Not including the public_header_files will make all headers public. | 96 | # Not including the public_header_files will make all headers public. |
| 97 | # | 97 | # |
| 98 | 98 | ||
| 99 | - s.source_files = "CNLiveICloudPicker/*.{h,m}" # 文件位置 | 99 | + s.source_files = "CNLiveICloudPicker/*" # 文件位置 |
| 100 | #s.exclude_files = "Classes/Exclude" | 100 | #s.exclude_files = "Classes/Exclude" |
| 101 | 101 | ||
| 102 | # s.public_header_files = "Classes/**/*.h" | 102 | # s.public_header_files = "Classes/**/*.h" |
CNLiveICloudPicker/CNICloudDocumentModel.h
0 → 100644
| 1 | +// | ||
| 2 | +// ICloudDocumentModel.h | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | + | ||
| 11 | +//NS_ASSUME_NONNULL_BEGIN | ||
| 12 | + | ||
| 13 | +@interface CNICloudDocumentModel : NSObject | ||
| 14 | + | ||
| 15 | +/** 路径 */ | ||
| 16 | +@property (strong, nonatomic) NSURL *fileURL; | ||
| 17 | +/** 文件的名称 | ||
| 18 | +eg. “/tmp/scratch.tiff” -> “/tmp/scratch” | ||
| 19 | +eg. “/tmp/” -> “/tmp” | ||
| 20 | +eg. “scratch..tiff” -> “scratch.” | ||
| 21 | + */ | ||
| 22 | +@property (copy, nonatomic) NSString *fileName; | ||
| 23 | +/** 是否有路径 */ | ||
| 24 | +@property (assign, nonatomic) Boolean fileIsExist; | ||
| 25 | +/** 文件的相关属性. Use: fileAttributes.fileSize() */ | ||
| 26 | +@property (copy, nonatomic) NSDictionary *fileAttributes; | ||
| 27 | + | ||
| 28 | ++ (CNICloudDocumentModel *)modelWithPath:(NSString *)path; | ||
| 29 | + | ||
| 30 | +@end | ||
| 31 | + | ||
| 32 | +//NS_ASSUME_NONNULL_END |
CNLiveICloudPicker/CNICloudDocumentModel.m
0 → 100644
| 1 | +// | ||
| 2 | +// ICloudDocumentModel.m | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "CNICloudDocumentModel.h" | ||
| 10 | +#import "CNICloudFileHelper.h" | ||
| 11 | + | ||
| 12 | +@implementation NSString (iCloud) | ||
| 13 | + | ||
| 14 | ++ (BOOL)isEmpty:(NSString *)string | ||
| 15 | +{ | ||
| 16 | + return string == nil || string.length == 0; | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +@end | ||
| 20 | + | ||
| 21 | +@implementation CNICloudDocumentModel | ||
| 22 | + | ||
| 23 | ++ (CNICloudDocumentModel *)modelWithPath:(NSString *)path { | ||
| 24 | + | ||
| 25 | + CNICloudDocumentModel *iCloudDocumentModel = [[CNICloudDocumentModel alloc]init]; | ||
| 26 | + | ||
| 27 | + if ([NSString isEmpty:path]) { | ||
| 28 | + return iCloudDocumentModel; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + iCloudDocumentModel.fileURL = [[NSURL alloc]initFileURLWithPath:path]; | ||
| 32 | + | ||
| 33 | + // 读取文件名 | ||
| 34 | + if (iCloudDocumentModel.fileURL) { | ||
| 35 | + NSString *pathString = [[NSString alloc]initWithString:iCloudDocumentModel.fileURL.lastPathComponent]; | ||
| 36 | + iCloudDocumentModel.fileName = [pathString stringByDeletingPathExtension]; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 40 | + iCloudDocumentModel.fileIsExist = [fileManager fileExistsAtPath:path]; | ||
| 41 | + // 获取文件相关属性 | ||
| 42 | + NSDictionary *fileAttributes = [CNICloudFileHelper fileAttrAtPath:path]; | ||
| 43 | + if (fileAttributes.count < 0) { | ||
| 44 | + return iCloudDocumentModel; | ||
| 45 | + } | ||
| 46 | + iCloudDocumentModel.fileAttributes = fileAttributes; | ||
| 47 | + | ||
| 48 | + return iCloudDocumentModel; | ||
| 49 | + | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | + | ||
| 53 | +@end |
CNLiveICloudPicker/CNICloudDocumentPickerController.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudDocumentPickerViewController.h | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <UIKit/UIKit.h> | ||
| 10 | + | ||
| 11 | +NS_ASSUME_NONNULL_BEGIN | ||
| 12 | + | ||
| 13 | +@interface CNICloudDocumentPickerController : UIDocumentPickerViewController | ||
| 14 | + | ||
| 15 | +/** 主题颜色 */ | ||
| 16 | +@property (strong, nonatomic) UIColor *themeColor; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +@end | ||
| 22 | + | ||
| 23 | +NS_ASSUME_NONNULL_END |
CNLiveICloudPicker/CNICloudDocumentPickerController.m
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudDocumentPickerViewController.m | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "CNICloudDocumentPickerController.h" | ||
| 10 | + | ||
| 11 | +@interface CNICloudDocumentPickerController () | ||
| 12 | + | ||
| 13 | +@end | ||
| 14 | + | ||
| 15 | +@implementation CNICloudDocumentPickerController | ||
| 16 | + | ||
| 17 | +- (void)viewDidLoad { | ||
| 18 | + [super viewDidLoad]; | ||
| 19 | + | ||
| 20 | + self.modalPresentationStyle = UIModalPresentationFullScreen; | ||
| 21 | + self.modalTransitionStyle = UIModalTransitionStyleCoverVertical; | ||
| 22 | + | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +- (void)viewWillAppear:(BOOL)animated { | ||
| 26 | + [super viewWillAppear:animated]; | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +- (void)viewWillDisappear:(BOOL)animated { | ||
| 30 | + [super viewWillDisappear:animated]; | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +/** 设置主题颜色 */ | ||
| 34 | +- (void)configuraThemeColor:(UIColor *)themeColor { | ||
| 35 | + [UIImageView appearance].tintColor = themeColor; | ||
| 36 | + [UITabBar appearance].tintColor = themeColor; | ||
| 37 | + [UIView appearanceWhenContainedInInstancesOfClasses:UIAlertController.self]; | ||
| 38 | + [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: themeColor} forState:UIControlStateNormal]; | ||
| 39 | + [UILabel appearance].tintColor = themeColor; | ||
| 40 | + [UIButton appearance].tintColor = themeColor; | ||
| 41 | + self.view.tintColor = themeColor; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +@end |
CNLiveICloudPicker/CNICloudDocumentPickerManager.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudDocumentPickerManager.h | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | + | ||
| 11 | +NS_ASSUME_NONNULL_BEGIN | ||
| 12 | + | ||
| 13 | +@interface CNICloudDocumentPickerManager : NSObject | ||
| 14 | + | ||
| 15 | +@end | ||
| 16 | + | ||
| 17 | +NS_ASSUME_NONNULL_END |
CNLiveICloudPicker/CNICloudDocumentPickerManager.m
0 → 100644
CNLiveICloudPicker/CNICloudFileHelper.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudFileHelper.h | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | + | ||
| 11 | +NS_ASSUME_NONNULL_BEGIN | ||
| 12 | + | ||
| 13 | +@interface CNICloudFileHelper : NSObject | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + 创建文件目录,如果不存在目录会创建目录 | ||
| 17 | + | ||
| 18 | + @param path 文件目录 | ||
| 19 | + @return 是否创建成功 | ||
| 20 | + */ | ||
| 21 | ++ (Boolean)createDirectoryAtPath:(NSString *)path; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + 获取单个文件大小 | ||
| 25 | + | ||
| 26 | + @param path 文件路径 | ||
| 27 | + @return 文件大小 | ||
| 28 | + */ | ||
| 29 | ++ (float)fileSizeAtPath:(NSString *)path; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + 获取文件属性 | ||
| 33 | + | ||
| 34 | + @param path 文件路径 | ||
| 35 | + @return 文件属性 | ||
| 36 | + */ | ||
| 37 | ++ (NSDictionary *)fileAttrAtPath:(NSString *)path; | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +/** | ||
| 41 | + 获取子文件夹的总大小 | ||
| 42 | + | ||
| 43 | + @param path 文件夹路径 | ||
| 44 | + @return 文件夹大小 | ||
| 45 | + */ | ||
| 46 | ++ (float)forderSizeAtPath:(NSString *)path; | ||
| 47 | + | ||
| 48 | +/** | ||
| 49 | + 是否是文件夹 | ||
| 50 | + | ||
| 51 | + @param path 目录路径 | ||
| 52 | + @return 是否 | ||
| 53 | + */ | ||
| 54 | ++ (BOOL)isDirectoryAtPath:(NSString *)path; | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + | ||
| 58 | +@end | ||
| 59 | + | ||
| 60 | +NS_ASSUME_NONNULL_END |
CNLiveICloudPicker/CNICloudFileHelper.m
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudFileHelper.m | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/12. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "CNICloudFileHelper.h" | ||
| 10 | + | ||
| 11 | +@implementation CNICloudFileHelper | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + 创建文件目录,如果不存在目录会创建目录 | ||
| 17 | + | ||
| 18 | + @param path 文件目录 | ||
| 19 | + @return 是否创建成功 | ||
| 20 | + */ | ||
| 21 | ++ (Boolean)createDirectoryAtPath:(NSString *)path{ | ||
| 22 | + | ||
| 23 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 24 | + Boolean result = [fileManager fileExistsAtPath:path]; | ||
| 25 | + if (result == NO) { | ||
| 26 | + BOOL isCreate = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil]; | ||
| 27 | + return isCreate; | ||
| 28 | + | ||
| 29 | + }else { | ||
| 30 | + return YES; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + 获取单个文件大小 | ||
| 37 | + | ||
| 38 | + @param path 文件路径 | ||
| 39 | + @return 文件大小 | ||
| 40 | + */ | ||
| 41 | ++ (float)fileSizeAtPath:(NSString *)path { | ||
| 42 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 43 | + BOOL isExists = [fileManager fileExistsAtPath:path]; | ||
| 44 | + if (!isExists) { | ||
| 45 | + return 0.0; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + NSDictionary *attributesDic = [fileManager attributesOfItemAtPath:path error:nil]; | ||
| 49 | + if (attributesDic) { | ||
| 50 | + return [attributesDic[NSFileSize] floatValue]; | ||
| 51 | + }else { | ||
| 52 | + return 0.0; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +/** | ||
| 58 | + 获取文件属性 | ||
| 59 | + | ||
| 60 | + @param path 文件路径 | ||
| 61 | + @return 文件属性 | ||
| 62 | + */ | ||
| 63 | ++ (NSDictionary *)fileAttrAtPath:(NSString *)path { | ||
| 64 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 65 | + BOOL isExists = [fileManager fileExistsAtPath:path]; | ||
| 66 | + if (!isExists) { | ||
| 67 | + return nil; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + NSDictionary *attributesDic = [fileManager attributesOfItemAtPath:path error:nil]; | ||
| 71 | + if (attributesDic > 0) { | ||
| 72 | + return attributesDic; | ||
| 73 | + }else { | ||
| 74 | + return nil; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | + | ||
| 80 | +/** | ||
| 81 | + 获取子文件夹的总大小 | ||
| 82 | + | ||
| 83 | + @param path 文件夹路径 | ||
| 84 | + @return 文件夹大小 | ||
| 85 | + */ | ||
| 86 | ++ (float)forderSizeAtPath:(NSString *)path { | ||
| 87 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 88 | + BOOL isExists = [fileManager fileExistsAtPath:path]; | ||
| 89 | + if (!isExists) { | ||
| 90 | + return 0.0; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + NSArray *subpaths = [fileManager subpathsAtPath:path]; | ||
| 94 | + if (subpaths.count <= 0) { | ||
| 95 | + return 0.0; | ||
| 96 | + }else { | ||
| 97 | + float fileSize = 0; | ||
| 98 | + | ||
| 99 | + for (NSString *subPath in subpaths) { | ||
| 100 | + NSString *fileAbsoluePath = [NSString stringWithFormat:@"%@/%@",path,subPath]; | ||
| 101 | + if ([CNICloudFileHelper isDirectoryAtPath:fileAbsoluePath]) { | ||
| 102 | + fileSize += [self fileSizeAtPath:fileAbsoluePath]; | ||
| 103 | + } else { | ||
| 104 | + fileSize += 0.0; | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + return fileSize; | ||
| 108 | + } | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | + | ||
| 112 | +/** | ||
| 113 | + 是否是文件夹 | ||
| 114 | + | ||
| 115 | + @param path 目录路径 | ||
| 116 | + @return 是否 | ||
| 117 | + */ | ||
| 118 | ++ (BOOL)isDirectoryAtPath:(NSString *)path { | ||
| 119 | + BOOL isDirectory = NO; | ||
| 120 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 121 | + BOOL isExists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory]; | ||
| 122 | + return isExists && isDirectory; | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | + | ||
| 126 | + | ||
| 127 | +@end |
CNLiveICloudPicker/CNICloudManager.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudManager.h | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/15. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import <Foundation/Foundation.h> | ||
| 10 | +#import <UIKit/UIKit.h> | ||
| 11 | +#import "CNICloudFileHelper.h" | ||
| 12 | +#import "CNICloudDocumentModel.h" | ||
| 13 | + | ||
| 14 | +NS_ASSUME_NONNULL_BEGIN | ||
| 15 | + | ||
| 16 | +@interface CNICloudManager : NSObject | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + 判断iCloud是否可用 | ||
| 20 | + | ||
| 21 | + @return 是否可用 | ||
| 22 | + */ | ||
| 23 | ++ (BOOL)iCloudEnable; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + 通过CNICloudDocument 打开关闭文件 | ||
| 27 | + | ||
| 28 | + @param url url | ||
| 29 | + @param callBack 文件数据,文件大小 | ||
| 30 | + */ | ||
| 31 | ++ (void)downloadWithDocumentURL:(NSURL *)url callBack:(void(^)(bool success ,NSData *data, float size)) callBack; | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | + 保存文件到本地 /Documents/iCloudBox 下 | ||
| 35 | + | ||
| 36 | + @param url 文件路径 | ||
| 37 | + @param outputPath 导出路径 | ||
| 38 | + @param maxSize 保存的最大尺寸 为 nil 忽略 | ||
| 39 | + @param conversationId 群聊为群 ID, 单聊为好友ID (即 会话ID) | ||
| 40 | + @param callBackContent 保存h的路径 url,是否保存成功,保存失败的描述 | ||
| 41 | + */ | ||
| 42 | ++ (void)saveWithDocumentURL:(NSURL *)url outputPath:(NSString *)outputPath maxSize:(float)maxSize conversationId:(NSString *)conversationId callBackContent:(void(^)(CNICloudDocumentModel *model, BOOL success, NSString * msg, NSInteger code))callBackContent; | ||
| 43 | + | ||
| 44 | +/** | ||
| 45 | + 文件是否在指定filePath存在 否则是否在iCloudBox存在 | ||
| 46 | + | ||
| 47 | + @param fileName 文件名(fileUrl.lastPathComponent) eg. doc.text | ||
| 48 | + @param filePath 指定路径 | ||
| 49 | + @return 文件路径 | ||
| 50 | + */ | ||
| 51 | ++ (NSURL *)documentIsExistsWithFileName:(NSString *)fileName filePath:(NSString *)filePath; | ||
| 52 | + | ||
| 53 | +/** | ||
| 54 | + 清楚本地缓存 | ||
| 55 | + | ||
| 56 | + @param filePath filePath 为空 清除所有缓存 | ||
| 57 | + @return 是否成功 | ||
| 58 | + */ | ||
| 59 | ++ (BOOL)clearICloudBoxCacheWhithFilePath:(NSString *)filePath; | ||
| 60 | + | ||
| 61 | +/** | ||
| 62 | + 异步获取iCloudBox 缓存大小 | ||
| 63 | + | ||
| 64 | + @param filePath 路径 | ||
| 65 | + @param callBack 返回大小 | ||
| 66 | + */ | ||
| 67 | ++ (void)asynciCloudBoxSizeWithFilePath:(NSString *)filePath CallBack:(void(^)(float size))callBack; | ||
| 68 | + | ||
| 69 | +@end | ||
| 70 | + | ||
| 71 | +NS_ASSUME_NONNULL_END | ||
| 72 | + | ||
| 73 | + | ||
| 74 | +NS_ASSUME_NONNULL_BEGIN | ||
| 75 | + | ||
| 76 | +@interface CNICloudDocument : UIDocument | ||
| 77 | + | ||
| 78 | +@property (nonatomic , strong) NSData *data; | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +@end | ||
| 82 | + | ||
| 83 | +NS_ASSUME_NONNULL_END | ||
| 84 | + | ||
| 85 | + |
CNLiveICloudPicker/CNICloudManager.m
0 → 100644
| 1 | +// | ||
| 2 | +// CNICloudManager.m | ||
| 3 | +// iCloud_测试 | ||
| 4 | +// | ||
| 5 | +// Created by 梁星国 on 2018/10/15. | ||
| 6 | +// Copyright © 2018年 梁星国. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#import "CNICloudManager.h" | ||
| 10 | +#import "CNICloudFileHelper.h" | ||
| 11 | +#import "CNICloudDocumentModel.h" | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +/** 存放的默认路径 */ | ||
| 15 | +#define kICloudBoxPath [NSString stringWithFormat:@"%@%@",NSHomeDirectory(),@"/Documents/iCloudBox/Doc/"] | ||
| 16 | + | ||
| 17 | +/** 存放下载路径 */ | ||
| 18 | +#define kICloudBoxDownLoadPath [NSString stringWithFormat:@"%@%@",NSHomeDirectory(),@"/Documents/iCloudBox/Doc/Download/"] | ||
| 19 | + | ||
| 20 | +#define code100 100 //写入文件成功 | ||
| 21 | +#define code101 101 //没有开启权限 | ||
| 22 | +#define code102 102 //文件下载失败 | ||
| 23 | +#define code103 103 //文件不能太大 | ||
| 24 | +#define code104 104 //文件夹无文件 | ||
| 25 | +#define code105 105 //文件写入失败 | ||
| 26 | +#define code106 106 //无数据 | ||
| 27 | +@implementation NSString (CNICloudManager) | ||
| 28 | + | ||
| 29 | ++ (BOOL)isEmpty:(NSString *)string | ||
| 30 | +{ | ||
| 31 | + return string == nil || string.length == 0; | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +@end | ||
| 35 | + | ||
| 36 | +@implementation CNICloudManager | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + 判断iCloud是否可用 | ||
| 40 | + | ||
| 41 | + @return 是否可用 | ||
| 42 | + */ | ||
| 43 | ++ (BOOL)iCloudEnable { | ||
| 44 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 45 | + NSURL *url = [fileManager URLForUbiquityContainerIdentifier:nil]; | ||
| 46 | + if (url) { | ||
| 47 | + return true; | ||
| 48 | + }else { | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | + | ||
| 55 | +/** | ||
| 56 | + 通过CNICloudDocument 打开关闭文件 | ||
| 57 | + | ||
| 58 | + @param url url | ||
| 59 | + @param callBack 文件数据,文件大小 | ||
| 60 | + */ | ||
| 61 | ++ (void)downloadWithDocumentURL:(NSURL *)url callBack:(void(^)(bool success ,NSData *data, float size)) callBack{ | ||
| 62 | + | ||
| 63 | + CNICloudDocument *iCloudDoc = [[CNICloudDocument alloc]initWithFileURL:url]; | ||
| 64 | + [iCloudDoc openWithCompletionHandler:^(BOOL success) { | ||
| 65 | + if (success) { | ||
| 66 | + | ||
| 67 | + __block float size = [CNICloudFileHelper fileSizeAtPath:url.path]; | ||
| 68 | + [iCloudDoc closeWithCompletionHandler:^(BOOL success) { | ||
| 69 | + !callBack ?: callBack( success,iCloudDoc.data,size); | ||
| 70 | + }]; | ||
| 71 | + | ||
| 72 | + }else { | ||
| 73 | + !callBack ?: callBack( success,nil,0.0); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + }]; | ||
| 77 | + | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +/** | ||
| 82 | + 保存文件到本地 /Documents/iCloudBox 下 | ||
| 83 | + | ||
| 84 | + @param url 文件路径 | ||
| 85 | + @param maxSize 保存的最大尺寸 为 nil 忽略 | ||
| 86 | + @param conversationId 群聊为群 ID, 单聊为好友ID (即 会话ID) | ||
| 87 | + @param callBackContent 保存h的路径 url,是否保存成功,保存失败的描述 | ||
| 88 | + */ | ||
| 89 | + | ||
| 90 | ++ (void)saveWithDocumentURL:(NSURL *)url outputPath:(NSString *)outputPath maxSize:(float)maxSize conversationId:(NSString *)conversationId callBackContent:(void(^)(CNICloudDocumentModel *model, BOOL success, NSString * msg, NSInteger code))callBackContent { | ||
| 91 | + | ||
| 92 | + if (![CNICloudManager iCloudEnable]) { | ||
| 93 | + callBackContent(nil, false, @"请在设置->AppleID、iCloud->iCloud中打开访问权限",code101); | ||
| 94 | + return; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"]; | ||
| 98 | + NSString *fileName = [array lastObject]; | ||
| 99 | + fileName = [fileName stringByRemovingPercentEncoding]; | ||
| 100 | + | ||
| 101 | + [CNICloudManager downloadWithDocumentURL:url callBack:^(bool success ,NSData *data, float size) { | ||
| 102 | + | ||
| 103 | + if (!success) { | ||
| 104 | + callBackContent(nil,false,[NSString stringWithFormat:@"文件下载失败"],code102); | ||
| 105 | + return; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + if (size > maxSize) { | ||
| 109 | + callBackContent(nil,false,[NSString stringWithFormat:@"文件不能大于%f",maxSize],code103); | ||
| 110 | + return; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + if ([NSString isEmpty:url.lastPathComponent]) { | ||
| 114 | + callBackContent(nil,false,[NSString stringWithFormat:@"文件夹无文件"],code104); | ||
| 115 | + return; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + if (data) { | ||
| 119 | + | ||
| 120 | + NSString *dataPath = [NSString string]; | ||
| 121 | + if ([NSString isEmpty:outputPath]) { | ||
| 122 | + dataPath = kICloudBoxDownLoadPath; | ||
| 123 | + }else { | ||
| 124 | + dataPath = outputPath; | ||
| 125 | + } | ||
| 126 | + NSURL *writeUrl = [[NSURL alloc]initFileURLWithPath:dataPath]; | ||
| 127 | + [CNICloudFileHelper createDirectoryAtPath:dataPath]; | ||
| 128 | + | ||
| 129 | + BOOL isWrite = [data writeToURL:writeUrl options:NSDataWritingAtomic error:nil]; | ||
| 130 | + | ||
| 131 | + if (isWrite) { | ||
| 132 | + callBackContent([CNICloudDocumentModel modelWithPath:writeUrl.path],YES,@"文件写入成功",code100); | ||
| 133 | + }else { | ||
| 134 | + callBackContent(nil, false,@"文件写入失败",code105); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + }else { | ||
| 138 | + callBackContent(nil, false, @"无数据",code106); | ||
| 139 | + return; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + }]; | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | + | ||
| 146 | +/** | ||
| 147 | + 文件是否在指定filePath存在 否则是否在iCloudBox存在 | ||
| 148 | + | ||
| 149 | + @param fileName 文件名(fileUrl.lastPathComponent) eg. doc.text | ||
| 150 | + @return 文件路径 | ||
| 151 | + */ | ||
| 152 | ++ (NSURL *)documentIsExistsWithFileName:(NSString *)fileName filePath:(NSString *)filePath{ | ||
| 153 | + | ||
| 154 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 155 | + NSString *tempPath = [NSString string]; | ||
| 156 | + if ([NSString isEmpty:filePath]) { | ||
| 157 | + tempPath = kICloudBoxDownLoadPath; | ||
| 158 | + }else { | ||
| 159 | + tempPath = filePath; | ||
| 160 | + } | ||
| 161 | + NSArray *childFilePaths = [fileManager subpathsAtPath:tempPath]; | ||
| 162 | + if (childFilePaths.count <= 0) { | ||
| 163 | + return nil; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + for (NSString *path in childFilePaths) { | ||
| 167 | + //读取文件名 | ||
| 168 | + NSString *checkPath = [NSString stringWithFormat:@"%@%@",tempPath,path]; | ||
| 169 | + NSURL *checkUrl = [[NSURL alloc]initFileURLWithPath:checkPath]; | ||
| 170 | + if ([fileName isEqualToString:checkUrl.lastPathComponent]) { | ||
| 171 | + return checkUrl; | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + return nil; | ||
| 176 | + | ||
| 177 | +} | ||
| 178 | + | ||
| 179 | + | ||
| 180 | +/** | ||
| 181 | + 清除本地缓存 | ||
| 182 | + | ||
| 183 | + @param filePath filePath 为空 清除所有缓存 | ||
| 184 | + @return 是否成功 | ||
| 185 | + */ | ||
| 186 | ++ (BOOL)clearICloudBoxCacheWhithFilePath:(NSString *)filePath { | ||
| 187 | + NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 188 | + if (!filePath) { | ||
| 189 | + NSURL *defultUrl = [NSURL fileURLWithPath:kICloudBoxPath]; | ||
| 190 | + return [fileManager removeItemAtURL:defultUrl error:nil]; | ||
| 191 | + } | ||
| 192 | + BOOL isRemove = [fileManager removeItemAtURL:[NSURL fileURLWithPath:filePath] error:nil]; | ||
| 193 | + return isRemove; | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | + | ||
| 197 | + | ||
| 198 | +/** | ||
| 199 | + 异步获取iCloudBox 缓存大小 | ||
| 200 | + | ||
| 201 | + @param filePath 路径 | ||
| 202 | + @param callBack 返回大小 | ||
| 203 | + */ | ||
| 204 | ++ (void)asynciCloudBoxSizeWithFilePath:(NSString *)filePath CallBack:(void(^)(float size))callBack { | ||
| 205 | + | ||
| 206 | + dispatch_queue_t global = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | ||
| 207 | + dispatch_async(global, ^{ | ||
| 208 | + NSString *dataPath = [NSString string]; | ||
| 209 | + if ([NSString isEmpty:filePath]) { | ||
| 210 | + dataPath = kICloudBoxPath; | ||
| 211 | + }else { | ||
| 212 | + dataPath = filePath; | ||
| 213 | + } | ||
| 214 | + float dataSize = [CNICloudFileHelper forderSizeAtPath:dataPath]; | ||
| 215 | + callBack(dataSize); | ||
| 216 | + }); | ||
| 217 | + | ||
| 218 | + | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | + | ||
| 222 | +@end | ||
| 223 | + | ||
| 224 | + | ||
| 225 | +@implementation CNICloudDocument : UIDocument | ||
| 226 | + | ||
| 227 | + | ||
| 228 | +- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError * _Nullable __autoreleasing *)outError { | ||
| 229 | + | ||
| 230 | + if ([contents isKindOfClass:[NSData class]]) { | ||
| 231 | + NSData *userContent = (NSData *)contents; | ||
| 232 | + self.data = userContent; | ||
| 233 | + } | ||
| 234 | + return YES; | ||
| 235 | + | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +@end | ||
| 239 | + | ||
| 240 | + |
CNLiveICloudPicker/CNICoudHeader.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNICoudHeader.h | ||
| 3 | +// CNLiveNetAdd | ||
| 4 | +// | ||
| 5 | +// Created by daojian on 2018/10/16. | ||
| 6 | +// Copyright © 2018年 cnlive. All rights reserved. | ||
| 7 | +// | ||
| 8 | + | ||
| 9 | +#ifndef CNICoudHeader_h | ||
| 10 | +#define CNICoudHeader_h | ||
| 11 | + | ||
| 12 | +#import "CNICloudManager.h" | ||
| 13 | +#import "CNICloudDocumentModel.h" | ||
| 14 | +#import "CNICloudDocumentPickerManager.h" | ||
| 15 | +#import "CNICloudDocumentPickerController.h" | ||
| 16 | +#import "CNICloudFileHelper.h" | ||
| 17 | + | ||
| 18 | +#endif /* CNICoudHeader_h */ | ||
| 19 | + |
CNLiveICloudPicker/UIAlertController+Blocks.h deleted
100755 → 0
| 1 | -// | ||
| 2 | -// UIAlertController+Blocks.h | ||
| 3 | -// UIAlertControllerBlocks | ||
| 4 | -// | ||
| 5 | -// Created by Ryan Maxwell on 11/09/14. | ||
| 6 | -// | ||
| 7 | -// The MIT License (MIT) | ||
| 8 | -// | ||
| 9 | -// Copyright (c) 2014 Ryan Maxwell | ||
| 10 | -// | ||
| 11 | -// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 12 | -// this software and associated documentation files (the "Software"), to deal in | ||
| 13 | -// the Software without restriction, including without limitation the rights to | ||
| 14 | -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 15 | -// the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 16 | -// subject to the following conditions: | ||
| 17 | -// | ||
| 18 | -// The above copyright notice and this permission notice shall be included in all | ||
| 19 | -// copies or substantial portions of the Software. | ||
| 20 | -// | ||
| 21 | -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 22 | -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 23 | -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 24 | -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 25 | -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 26 | -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | -// | ||
| 28 | - | ||
| 29 | -#import <UIKit/UIKit.h> | ||
| 30 | - | ||
| 31 | -#if TARGET_OS_IOS | ||
| 32 | -typedef void (^UIAlertControllerPopoverPresentationControllerBlock) (UIPopoverPresentationController * __nonnull popover); | ||
| 33 | -#endif | ||
| 34 | -typedef void (^UIAlertControllerCompletionBlock) (UIAlertController * __nonnull controller, UIAlertAction * __nonnull action, NSInteger buttonIndex); | ||
| 35 | - | ||
| 36 | -@interface UIAlertController (Blocks) | ||
| 37 | - | ||
| 38 | -+ (nonnull instancetype)showInViewController:(nonnull UIViewController *)viewController | ||
| 39 | - withTitle:(nullable NSString *)title | ||
| 40 | - message:(nullable NSString *)message | ||
| 41 | - preferredStyle:(UIAlertControllerStyle)preferredStyle | ||
| 42 | - cancelButtonTitle:(nullable NSString *)cancelButtonTitle | ||
| 43 | - destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle | ||
| 44 | - otherButtonTitles:(nullable NSArray *)otherButtonTitles | ||
| 45 | -#if TARGET_OS_IOS | ||
| 46 | - popoverPresentationControllerBlock:(nullable UIAlertControllerPopoverPresentationControllerBlock)popoverPresentationControllerBlock | ||
| 47 | -#endif | ||
| 48 | - tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock; | ||
| 49 | - | ||
| 50 | -+ (nonnull instancetype)showAlertInViewController:(nonnull UIViewController *)viewController | ||
| 51 | - withTitle:(nullable NSString *)title | ||
| 52 | - message:(nullable NSString *)message | ||
| 53 | - cancelButtonTitle:(nullable NSString *)cancelButtonTitle | ||
| 54 | - destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle | ||
| 55 | - otherButtonTitles:(nullable NSArray *)otherButtonTitles | ||
| 56 | - tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock; | ||
| 57 | - | ||
| 58 | - | ||
| 59 | -+ (nonnull instancetype)showActionSheetInViewController:(nonnull UIViewController *)viewController | ||
| 60 | - withTitle:(nullable NSString *)title | ||
| 61 | - message:(nullable NSString *)message | ||
| 62 | - cancelButtonTitle:(nullable NSString *)cancelButtonTitle | ||
| 63 | - destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle | ||
| 64 | - otherButtonTitles:(nullable NSArray *)otherButtonTitles | ||
| 65 | -#if TARGET_OS_IOS | ||
| 66 | - popoverPresentationControllerBlock:(nullable UIAlertControllerPopoverPresentationControllerBlock)popoverPresentationControllerBlock | ||
| 67 | -#endif | ||
| 68 | - tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock; | ||
| 69 | - | ||
| 70 | - | ||
| 71 | -@property (readonly, nonatomic) BOOL visible; | ||
| 72 | -@property (readonly, nonatomic) NSInteger cancelButtonIndex; | ||
| 73 | -@property (readonly, nonatomic) NSInteger firstOtherButtonIndex; | ||
| 74 | -@property (readonly, nonatomic) NSInteger destructiveButtonIndex; | ||
| 75 | - | ||
| 76 | -@end |
CNLiveICloudPicker/UIAlertController+Blocks.m deleted
100755 → 0
| 1 | -// | ||
| 2 | -// UIAlertController+Blocks.m | ||
| 3 | -// UIAlertControllerBlocks | ||
| 4 | -// | ||
| 5 | -// Created by Ryan Maxwell on 11/09/14. | ||
| 6 | -// | ||
| 7 | -// The MIT License (MIT) | ||
| 8 | -// | ||
| 9 | -// Copyright (c) 2014 Ryan Maxwell | ||
| 10 | -// | ||
| 11 | -// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 12 | -// this software and associated documentation files (the "Software"), to deal in | ||
| 13 | -// the Software without restriction, including without limitation the rights to | ||
| 14 | -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 15 | -// the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 16 | -// subject to the following conditions: | ||
| 17 | -// | ||
| 18 | -// The above copyright notice and this permission notice shall be included in all | ||
| 19 | -// copies or substantial portions of the Software. | ||
| 20 | -// | ||
| 21 | -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 22 | -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 23 | -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 24 | -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 25 | -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 26 | -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | -// | ||
| 28 | - | ||
| 29 | -#import "UIAlertController+Blocks.h" | ||
| 30 | - | ||
| 31 | -static NSInteger const UIAlertControllerBlocksCancelButtonIndex = 0; | ||
| 32 | -static NSInteger const UIAlertControllerBlocksDestructiveButtonIndex = 1; | ||
| 33 | -static NSInteger const UIAlertControllerBlocksFirstOtherButtonIndex = 2; | ||
| 34 | - | ||
| 35 | -@interface UIViewController (UACB_Topmost) | ||
| 36 | - | ||
| 37 | -- (UIViewController *)uacb_topmost; | ||
| 38 | - | ||
| 39 | -@end | ||
| 40 | - | ||
| 41 | -@implementation UIAlertController (Blocks) | ||
| 42 | - | ||
| 43 | -+ (instancetype)showInViewController:(UIViewController *)viewController | ||
| 44 | - withTitle:(NSString *)title | ||
| 45 | - message:(NSString *)message | ||
| 46 | - preferredStyle:(UIAlertControllerStyle)preferredStyle | ||
| 47 | - cancelButtonTitle:(NSString *)cancelButtonTitle | ||
| 48 | - destructiveButtonTitle:(NSString *)destructiveButtonTitle | ||
| 49 | - otherButtonTitles:(NSArray *)otherButtonTitles | ||
| 50 | -#if TARGET_OS_IOS | ||
| 51 | - popoverPresentationControllerBlock:(void(^)(UIPopoverPresentationController *popover))popoverPresentationControllerBlock | ||
| 52 | -#endif | ||
| 53 | - tapBlock:(UIAlertControllerCompletionBlock)tapBlock | ||
| 54 | -{ | ||
| 55 | - UIAlertController *strongController = [self alertControllerWithTitle:title | ||
| 56 | - message:message | ||
| 57 | - preferredStyle:preferredStyle]; | ||
| 58 | - | ||
| 59 | - __weak UIAlertController *controller = strongController; | ||
| 60 | - | ||
| 61 | - if (cancelButtonTitle) { | ||
| 62 | - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle | ||
| 63 | - style:UIAlertActionStyleCancel | ||
| 64 | - handler:^(UIAlertAction *action){ | ||
| 65 | - if (tapBlock) { | ||
| 66 | - tapBlock(controller, action, UIAlertControllerBlocksCancelButtonIndex); | ||
| 67 | - } | ||
| 68 | - }]; | ||
| 69 | - [controller addAction:cancelAction]; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - if (destructiveButtonTitle) { | ||
| 73 | - UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:destructiveButtonTitle | ||
| 74 | - style:UIAlertActionStyleDestructive | ||
| 75 | - handler:^(UIAlertAction *action){ | ||
| 76 | - if (tapBlock) { | ||
| 77 | - tapBlock(controller, action, UIAlertControllerBlocksDestructiveButtonIndex); | ||
| 78 | - } | ||
| 79 | - }]; | ||
| 80 | - [controller addAction:destructiveAction]; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - for (NSUInteger i = 0; i < otherButtonTitles.count; i++) { | ||
| 84 | - NSString *otherButtonTitle = otherButtonTitles[i]; | ||
| 85 | - | ||
| 86 | - UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle | ||
| 87 | - style:UIAlertActionStyleDefault | ||
| 88 | - handler:^(UIAlertAction *action){ | ||
| 89 | - if (tapBlock) { | ||
| 90 | - tapBlock(controller, action, UIAlertControllerBlocksFirstOtherButtonIndex + i); | ||
| 91 | - } | ||
| 92 | - }]; | ||
| 93 | - [controller addAction:otherAction]; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | -#if TARGET_OS_IOS | ||
| 97 | - if (popoverPresentationControllerBlock) { | ||
| 98 | - popoverPresentationControllerBlock(controller.popoverPresentationController); | ||
| 99 | - } | ||
| 100 | -#endif | ||
| 101 | - | ||
| 102 | - [viewController.uacb_topmost presentViewController:controller animated:YES completion:nil]; | ||
| 103 | - | ||
| 104 | - return controller; | ||
| 105 | -} | ||
| 106 | - | ||
| 107 | -+ (instancetype)showAlertInViewController:(UIViewController *)viewController | ||
| 108 | - withTitle:(NSString *)title | ||
| 109 | - message:(NSString *)message | ||
| 110 | - cancelButtonTitle:(NSString *)cancelButtonTitle | ||
| 111 | - destructiveButtonTitle:(NSString *)destructiveButtonTitle | ||
| 112 | - otherButtonTitles:(NSArray *)otherButtonTitles | ||
| 113 | - tapBlock:(UIAlertControllerCompletionBlock)tapBlock | ||
| 114 | -{ | ||
| 115 | - return [self showInViewController:viewController | ||
| 116 | - withTitle:title | ||
| 117 | - message:message | ||
| 118 | - preferredStyle:UIAlertControllerStyleAlert | ||
| 119 | - cancelButtonTitle:cancelButtonTitle | ||
| 120 | - destructiveButtonTitle:destructiveButtonTitle | ||
| 121 | - otherButtonTitles:otherButtonTitles | ||
| 122 | -#if TARGET_OS_IOS | ||
| 123 | - popoverPresentationControllerBlock:nil | ||
| 124 | -#endif | ||
| 125 | - tapBlock:tapBlock]; | ||
| 126 | -} | ||
| 127 | - | ||
| 128 | -+ (instancetype)showActionSheetInViewController:(UIViewController *)viewController | ||
| 129 | - withTitle:(NSString *)title | ||
| 130 | - message:(NSString *)message | ||
| 131 | - cancelButtonTitle:(NSString *)cancelButtonTitle | ||
| 132 | - destructiveButtonTitle:(NSString *)destructiveButtonTitle | ||
| 133 | - otherButtonTitles:(NSArray *)otherButtonTitles | ||
| 134 | -#if TARGET_OS_IOS | ||
| 135 | - popoverPresentationControllerBlock:(void(^)(UIPopoverPresentationController *popover))popoverPresentationControllerBlock | ||
| 136 | -#endif | ||
| 137 | - tapBlock:(UIAlertControllerCompletionBlock)tapBlock | ||
| 138 | -{ | ||
| 139 | - return [self showInViewController:viewController | ||
| 140 | - withTitle:title | ||
| 141 | - message:message | ||
| 142 | - preferredStyle:UIAlertControllerStyleActionSheet | ||
| 143 | - cancelButtonTitle:cancelButtonTitle | ||
| 144 | - destructiveButtonTitle:destructiveButtonTitle | ||
| 145 | - otherButtonTitles:otherButtonTitles | ||
| 146 | -#if TARGET_OS_IOS | ||
| 147 | - popoverPresentationControllerBlock:popoverPresentationControllerBlock | ||
| 148 | -#endif | ||
| 149 | - tapBlock:tapBlock]; | ||
| 150 | -} | ||
| 151 | - | ||
| 152 | -#pragma mark - | ||
| 153 | - | ||
| 154 | -- (BOOL)visible | ||
| 155 | -{ | ||
| 156 | - return self.view.superview != nil; | ||
| 157 | -} | ||
| 158 | - | ||
| 159 | -- (NSInteger)cancelButtonIndex | ||
| 160 | -{ | ||
| 161 | - return UIAlertControllerBlocksCancelButtonIndex; | ||
| 162 | -} | ||
| 163 | - | ||
| 164 | -- (NSInteger)firstOtherButtonIndex | ||
| 165 | -{ | ||
| 166 | - return UIAlertControllerBlocksFirstOtherButtonIndex; | ||
| 167 | -} | ||
| 168 | - | ||
| 169 | -- (NSInteger)destructiveButtonIndex | ||
| 170 | -{ | ||
| 171 | - return UIAlertControllerBlocksDestructiveButtonIndex; | ||
| 172 | -} | ||
| 173 | - | ||
| 174 | -@end | ||
| 175 | - | ||
| 176 | -@implementation UIViewController (UACB_Topmost) | ||
| 177 | - | ||
| 178 | -- (UIViewController *)uacb_topmost | ||
| 179 | -{ | ||
| 180 | - UIViewController *topmost = self; | ||
| 181 | - | ||
| 182 | - UIViewController *above; | ||
| 183 | - while ((above = topmost.presentedViewController)) { | ||
| 184 | - topmost = above; | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - return topmost; | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -@end |