Skip to content

Commit

Permalink
更新工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
ligang committed Dec 21, 2018
1 parent 31d46ba commit aa1281f
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 132 deletions.
6 changes: 6 additions & 0 deletions LGApplications.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CECFE8E421A659DC003775A3 /* CommonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CECFE8E121A659DB003775A3 /* CommonCell.m */; };
CECFE8E721A65BAF003775A3 /* LGToastView.m in Sources */ = {isa = PBXBuildFile; fileRef = CECFE8E621A65BAF003775A3 /* LGToastView.m */; };
CED040FE1F63C99000C8B441 /* LGRollView.m in Sources */ = {isa = PBXBuildFile; fileRef = CED040FD1F63C99000C8B441 /* LGRollView.m */; };
CED1541221CCB8D80059A9D7 /* LGImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CED1541121CCB8D80059A9D7 /* LGImageManager.m */; };
CEDFD7F021A502A9000C0D4F /* IndexSectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = CEDFD7EF21A502A9000C0D4F /* IndexSectionView.m */; };
CEDFD7FA21A50F6C000C0D4F /* LocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CEDFD7F921A50F6C000C0D4F /* LocationManager.m */; };
CEE768751EEA5A670093514F /* GradientAnimationDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE768741EEA5A670093514F /* GradientAnimationDemo.m */; };
Expand Down Expand Up @@ -129,6 +130,8 @@
CECFE8E621A65BAF003775A3 /* LGToastView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGToastView.m; sourceTree = "<group>"; };
CED040FC1F63C99000C8B441 /* LGRollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGRollView.h; sourceTree = "<group>"; };
CED040FD1F63C99000C8B441 /* LGRollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGRollView.m; sourceTree = "<group>"; };
CED1541021CCB8D80059A9D7 /* LGImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGImageManager.h; sourceTree = "<group>"; };
CED1541121CCB8D80059A9D7 /* LGImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGImageManager.m; sourceTree = "<group>"; };
CEDFD7EE21A502A9000C0D4F /* IndexSectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexSectionView.h; sourceTree = "<group>"; };
CEDFD7EF21A502A9000C0D4F /* IndexSectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IndexSectionView.m; sourceTree = "<group>"; };
CEDFD7F821A50F6C000C0D4F /* LocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocationManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -226,6 +229,8 @@
CE45DF0C20C5382000F33D4D /* KeyChainStore.m */,
CE008BF31EE7CA3C00318D98 /* NSUtil.h */,
CE008BF41EE7CA3C00318D98 /* NSUtil.m */,
CED1541021CCB8D80059A9D7 /* LGImageManager.h */,
CED1541121CCB8D80059A9D7 /* LGImageManager.m */,
CEDFD7F821A50F6C000C0D4F /* LocationManager.h */,
CEDFD7F921A50F6C000C0D4F /* LocationManager.m */,
);
Expand Down Expand Up @@ -593,6 +598,7 @@
CECFE8E721A65BAF003775A3 /* LGToastView.m in Sources */,
CE6040D21EE5316E0089C945 /* main.m in Sources */,
CE008C131EE7FEB200318D98 /* LGPickerView.m in Sources */,
CED1541221CCB8D80059A9D7 /* LGImageManager.m in Sources */,
CEE768751EEA5A670093514F /* GradientAnimationDemo.m in Sources */,
CECFE8E421A659DC003775A3 /* CommonCell.m in Sources */,
CE45DF0E20C5382000F33D4D /* KeyChainStore.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
3 changes: 3 additions & 0 deletions LGApplications/Util/Category/NSDictionary+Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

@interface NSDictionary (Extension)
- (NSString*)stringForKey:(NSString*)key;
- (int)intForKey:(NSString*)key;
- (float)floatForKey:(NSString*)key;
- (double)doubleForKey:(NSString*)key;
- (NSDictionary *)removeNull;
@end

Expand Down
9 changes: 9 additions & 0 deletions LGApplications/Util/Category/NSDictionary+Extension.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ - (NSString*)stringForKey:(NSString*)key
return retObj;
}

- (int)intForKey:(NSString*)key{
return [self stringForKey:key].intValue;
}
- (float)floatForKey:(NSString*)key{
return [self stringForKey:key].floatValue;
}
- (double)doubleForKey:(NSString*)key{
return [self stringForKey:key].doubleValue;
}


- (NSDictionary *)removeNull{
Expand Down
3 changes: 3 additions & 0 deletions LGApplications/Util/Category/NSString+Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
@property (nonatomic,copy,readonly) NSString *sha1;

/** 对应的URL*/
@property (nonatomic,copy,readonly) NSURL *url;

/** 是不是空字符串*/
- (BOOL)isEmptyString;

Expand Down
3 changes: 3 additions & 0 deletions LGApplications/Util/Category/NSString+Extension.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ -(NSString *)sha1{
return [result copy];
}

- (NSURL *)url{
return [NSURL URLWithString:self];
}

/** 是不是空字符串*/
- (BOOL)isEmptyString{
Expand Down
2 changes: 1 addition & 1 deletion LGApplications/Util/Category/UIView+Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef enum {
/** 设置渐变色*/
- (void)setGradientColors:(NSArray *)colors direction:(ColorDirection)direction;

/** 移除所以子控件*/
/** 移除所有子控件*/
- (void)removeAllSubviews;

@end
21 changes: 21 additions & 0 deletions LGApplications/Util/LGUtil/LGImageManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// LGImageManager.h
// H3
//
// Created by 李刚 on 2018/6/8.
// Copyright © 2018年 Mr.Lee. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Photos/Photos.h>

@interface LGImageManager : NSObject
+ (instancetype)manager;
+ (void)deallocManager;
+ (PHAuthorizationStatus)authorizationStatus;

+ (void)requestAuthorizationWithType:(UIImagePickerControllerSourceType)type allowed:(void (^)(BOOL allowed))result;

/** 必须实现UIImagePickerControllerDelegate里的代理方法 && UIViewController的子类*/
+ (void)selectImageWithType:(UIImagePickerControllerSourceType)type allowEdit:(BOOL)allow pickerDelegate:(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>)delegate;
@end
111 changes: 111 additions & 0 deletions LGApplications/Util/LGUtil/LGImageManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// LGImageManager.m
// H3
//
// Created by 李刚 on 2018/6/8.
// Copyright © 2018年 Mr.Lee. All rights reserved.
//

#import "LGImageManager.h"

#define kHttpRequestHeadContentTypeValueMultipart @"multipart/form-data; boundary=h3uploadimage"
#define kHttpRequestHeadContentTypeKey @"Content-Type"
#define kHttpRequestHeadBoundaryValue @"h3uploadimage"
#define kHttpRequestContentDisposition @"Content-Disposition: form-data"

@interface LGImageManager ()

@end



@implementation LGImageManager
static LGImageManager *manager;
static dispatch_once_t onceToken;

+ (instancetype)manager {
dispatch_once(&onceToken, ^{
manager = [[self alloc] init];
});
return manager;
}

+ (void)deallocManager {
onceToken = 0;
manager = nil;
}


+ (PHAuthorizationStatus)authorizationStatus {
return [PHPhotoLibrary authorizationStatus];
}


+ (void)requestAuthorizationWithType:(UIImagePickerControllerSourceType)type allowed:(void (^)(BOOL allowed))result
{
NSString *name = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleDisplayName"];
NSString *alert = [NSString stringWithFormat:@"请在iPhone的“设置-隐私-相机”选项中,允许“%@”访问你的相机",name];
PHAuthorizationStatus currentStatus = [PHPhotoLibrary authorizationStatus];
switch (currentStatus) {
case PHAuthorizationStatusAuthorized://已授权,可使用
{
result(YES);
break;
}
case PHAuthorizationStatusNotDetermined://未进行授权选择
{
//则再次请求授权
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
result(YES);
}
else{
//用户拒绝授权
dispatch_async(dispatch_get_main_queue(), ^{

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:alert preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
[alertVC addAction:cancel];
[[NSUtil currentController] presentViewController:alertVC animated:YES completion:nil];
});
result(NO);
}
}];

break;
}
default://用户拒绝授权/未授权
{

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:alert preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
[alertVC addAction:cancel];
[[NSUtil currentController] presentViewController:alertVC animated:YES completion:nil];
result(NO);
break;
}
}
}

+ (void)selectImageWithType:(UIImagePickerControllerSourceType)type allowEdit:(BOOL)allow pickerDelegate:(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) delegate {

[LGImageManager requestAuthorizationWithType:type allowed:^(BOOL allowed) {
if (allowed == YES && [UIImagePickerController isSourceTypeAvailable:type]) {

UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.view.backgroundColor = [UIColor whiteColor];
controller.sourceType = type;
controller.delegate = delegate;
controller.allowsEditing = allow;

if ([delegate isKindOfClass:UIViewController.class]) {
UIViewController *sender = (UIViewController *)delegate;
[sender.navigationController presentViewController:controller animated:YES completion:nil];
}else{
NSLog(@"Error: delegate 必须是UIViewController的子类");
}
}
}];
}

@end
31 changes: 6 additions & 25 deletions LGApplications/Util/LGUtil/NSUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,8 @@ typedef void(^ResultBlock)(NSDictionary *result);
typedef void(^StringBlock)(NSString *text);
typedef void(^CompleteBlock)(void);


typedef NS_ENUM(NSInteger, NetWorkStatus) {
NetWorkStatusUnknown = -1, // 未知
NetWorkStatusNotReachable = 0, // 无网络
NetWorkStatusReachableViaWWAN = 1, // GPRS
NetWorkStatusReachableViaWiFi = 2, // WiFi
};


typedef NS_ENUM(NSInteger, NetWorkType) {
NetWorkTypeUnknown = -1, // 未知
NetWorkTypeNotReachable = 0, // 无网络
NetWorkTypeReachableViaWiFi = 1, // WiFi
NetWorkTypeReachableVia2G = 2, // 2G
NetWorkTypeReachableVia3G = 3, // 3G
NetWorkTypeReachableVia4G = 4, // 4G
};

@interface NSUtil : NSObject

#pragma mark - 网络
/** 获取网络状态*/
+ (NetWorkStatus)getNetWorkStatus;

/** 获取网络类型*/
+ (NetWorkType)getNetWorkType;

#pragma mark - 设备
/** 获取版本号*/
+ (NSString *)getAppVersion;
Expand All @@ -64,6 +39,8 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
/** 设置导航栏黑线*/
+ (void)setNavigationBarLine:(UIView *)view hidden:(BOOL)hidden;

+ (UIViewController *)currentController;

#pragma mark - NSUserDefaults
+ (void)saveValue:(id)value forKey:(NSString *)key;
+ (id)getValueForKey:(NSString *)key;
Expand Down Expand Up @@ -158,4 +135,8 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
+ (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size bold:(BOOL)bold;
+ (UIFont *)fontWithFamily:(NSString *)family name:(NSString *)name size:(CGFloat)size;


#pragma mark - HTML to String
+ (NSAttributedString *)htmlToAttribute:(NSString *)html;
+ (NSString *)attributeToHtml:(NSAttributedString *)attributeString;
@end
Loading

0 comments on commit aa1281f

Please sign in to comment.