1,键盘输入去除emoji表情
- (NSString *)chooseStringContainsEmoji:(NSString *)string
{
// 过滤所有表情。returnValue为NO表示不含有表情,YES表示含有表情
__block NSMutableString *returnValueString = [NSMutableString string];
[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
const unichar hs = [substring characterAtIndex:0];
if (0xd800 <= hs && hs <= 0xdbff) {
if (substring.length > 1) {
const unichar ls = [substring characterAtIndex:1];
const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
if (0x1d000 <= uc && uc <= 0x1f77f) {
substring = @"";
}
}
} else if (substringRange.length > 1) {
substring = @"";
} else {
// non surrogate
if (0x2100 <= hs && hs <= 0x27ff) {
substring = @"";
} else if (0x2B05 <= hs && hs <= 0x2b07) {
substring = @"";
} else if (0x2934 <= hs && hs <= 0x2935) {
substring = @"";
} else if (0x3297 <= hs && hs <= 0x3299) {
substring = @"";
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
substring = @"";
}
}
[returnValueString appendString:substring];
}];
return returnValueString;
}
2,指纹识别判断
+ (void)fingerScanWithFallbakTitle:(NSString *)fallbackTitle andTitle:(NSString *)title andResult:(fingerScanResultBlock)block
{
//初始化上下文对象
LAContext* context = [[LAContext alloc] init];
context.localizedFallbackTitle = fallbackTitle;
//错误对象
NSError* error = nil;
NSString* result = title;
//首先使用canEvaluatePolicy 判断设备支持状态
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
//支持指纹验证
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
block(success,error.code);
});
}];
}else{
dispatch_async(dispatch_get_main_queue(), ^{
block(NO,error.code);
});
}
}
设备是否支持指纹识别判断
+ (void)isDeviceSupportFingerScanWithBlock:(fingerScanResultBlock)block{
LAContext* context = [[LAContext alloc] init];
NSError* error = nil;
if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]){
dispatch_async(dispatch_get_main_queue(), ^{
block(YES,error.code);
});
}else{
dispatch_async(dispatch_get_main_queue(), ^{
block(NO,error.code);
});
}
3,图片压缩变形处理
imageView.contentMode=UIViewContentModeScaleAspectFill;
imageView.clipsToBounds=YES;
图片拉伸变形处理
+ (UIImage *)resizableImageWithName:(NSString *)imageName
{
// 加载原有图片
UIImage *norImage = [UIImage imageNamed:imageName];
// 获取原有图片的宽高的一半
CGFloat w = norImage.size.width * 0.5;
CGFloat h = norImage.size.height * 0.5;
// 生成可以拉伸指定位置的图片
UIImage *newImage = [norImage resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];
returnnewImage;}
4检测设备是否越狱
[[NSFileManager defaultManager] fileExistsAtPath:@"/private/var/lib/apt/"];
5,tableView分割线顶头
-(void)viewDidLayoutSubviews {
if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
[self setSeparatorInset:UIEdgeInsetsZero];
}
if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
[self setLayoutMargins:UIEdgeInsetsZero];
}
}
6,DES加解密
/* 3DES解密 */
- (NSString *)decrypt3DES:(NSString *)key iv:(NSString *)iv
{
NSData *encryptData = [Base64 decode:self];
size_t plainTextBufferSize = [encryptData length];
const void *vplainText = [encryptData bytes];
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes = 0;
bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
bufferPtr = malloc(bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
const void *vkey = (const void *)[key UTF8String];
const void *vinitVec = (const void *)[iv UTF8String];
ccStatus = CCCrypt(kCCDecrypt,
kCCAlgorithm3DES,
kCCOptionPKCS7Padding,
vkey,
kCCKeySize3DES,
vinitVec,
vplainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
NSString *result = [[NSString alloc] initWithData:[NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes] encoding:NSUTF8StringEncoding];
free(bufferPtr);
return result;
}
/* 3DES加密 */
- (NSString *)encrypt3DES:(NSString *)key iv:(NSString *)iv
{
NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
size_t plainTextBufferSize = [data length];
const void *vplainText = (const void *)[data bytes];
CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t movedBytes = 0;
bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
bufferPtr = malloc(bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
const void *vkey = (const void *)[key UTF8String];
const void *vinitVec = (const void *)[iv UTF8String];
ccStatus = CCCrypt(kCCEncrypt,
kCCAlgorithm3DES,
kCCOptionPKCS7Padding,
vkey,
kCCKeySize3DES,
vinitVec,
vplainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);
NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
NSString *result = [Base64 encode:myData];
free(bufferPtr);
return result;
}
截屏
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//1.开启图形上下文对象 (bitmap)
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
//2.获取图形上下文对象
CGContextRef ctx = UIGraphicsGetCurrentContext();
//3.调用layer的renderInContext:作用是把指定view上的内容渲染到图形上下文中
[self.view.layer renderInContext:ctx];
//4.从图形上下文中获取图片
UIImage * getImage = UIGraphicsGetImageFromCurrentImageContext();
//5.结束图形上下文对象
UIGraphicsEndImageContext();
//6.使用图片
UIImageWriteToSavedPhotosAlbum(getImage, nil, nil,nil);
});