一.项目使用第三方:
platform:ios,'9.0'
use_frameworks!
inhibit_all_warnings!
target '***' do
pod 'AFNetworking'
pod 'RMQClient'
pod 'SwiftyJSON'
pod 'DZNEmptyDataSet'
pod 'Masonry'
pod 'MJRefresh'
pod 'MQTTClient'
pod 'LookinServer', :configurations => ['Debug']
end
没用过第三方学习:
1.RMQClient
RabbitMQ是流行的开源消息队列系统,用erlang语言开发。RabbitMQ是AMQP(高级消息队列协议)的标准实现。
参考链接:
http://www.rabbitmq.com/tutorials/tutorial-one-objectivec.html
https://blog.csdn.net/pdunderstand/article/details/52288417
2.MQTTClient
MQTT 是IBM开发的一个即时通讯协议,有可能成为物联网的重要组成部分。该协议支持所有平台,几乎可以把所有联网物品和外部连接起来,被用来当做传感器和致动器(比如通过Twitter让房屋联网)的通信协议 ----------------------百度词条解释
应用场景:
MQTT是一个设计得非常出色的传输层协议,在移动消息、物联网、车联网、智能硬件甚至能源勘探等领域有着广泛的应用。1个字节报头、2个字节心跳、消息QoS支持等设计,非常适合在低带宽、不可靠网络、嵌入式设备上应用。
参考链接:
https://www.jianshu.com/p/d725e597b006
https://www.jianshu.com/p/80ea4507ca74
3.LookinServer
Free macOS app for iOS view debugging.
参考链接:
https://github.com/QMUI/LookinServer
https://www.jianshu.com/p/9733646afa59
优秀代码:
1.单例的使用:
+ (instancetype _Nonnull)shared {
static id sharedInstance = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
2.枚举的使用:
typedef NS_ENUM(NSInteger, FunctionOption) {
FUN_GetNumber = 1 << 0, // 取等位号
FUN_CallNumber = 1 << 1, // 叫号
FUN_Leader = 1 << 2, // 领位
FUN_PreCheck = 1 << 3, // 预订查询
FUN_ClearNumber = 1 << 4, // 清号
FUN_AbsentSearch = 1 << 5, // 未到齐查询
FUN_EmptySeatSearch = 1 << 6, // 余位查询
FUN_Old_EmptySeatSearch = 1 << 7, // 余位查询老界面
FUN_Setting = 1 << 8, // 设置
};
3.ExternalAccessory框架:
和外部设备相关的一个框架。
ExternalAccessory框架的主要功能,就是提供一个管道,让外围设备可以和基于iOS系统的设备进行通讯。
参考链接:
https://www.jianshu.com/p/9a5a8e225551
4.JSPatch使用:
参考链接:
https://www.jianshu.com/p/b73883799c71
5.排序:
[_arrModel sortUsingComparator:^NSComparisonResult(TableStatusModel * _Nonnull obj1, TableStatusModel * _Nonnull obj2) {
NSNumber *tableNo1 = [NSNumber numberWithInteger:[obj1.statusNo integerValue]];
NSNumber *tableNo2 = [NSNumber numberWithInteger:[obj2.statusNo integerValue]];
return [tableNo1 compare:tableNo2];
}];
6.iOS手电筒的如何开启和关闭:
#import "ViewController.h"
#import
@interface ViewController ()
@property (nonatomic, strong) AVCaptureDevice *device;
@property (nonatomic,assign) BOOL lightOn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
/**
* hasTorch :返回YES表名手机上有手电筒
*/
if (![_device hasTorch]) {
NSLog(@"手电筒坏了");
return;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_lightOn = !_lightOn;
//根据ligthOn状态判断打开还是关闭
if (_lightOn) {
//开启手电筒
[_device lockForConfiguration:nil];
[_device setTorchMode:AVCaptureTorchModeOn];
[_device unlockForConfiguration];
}else{
//关闭手电筒
[_device lockForConfiguration:nil];
[_device setTorchMode:AVCaptureTorchModeOff];
[_device unlockForConfiguration];
}
}
@end
参考链接:
https://www.jianshu.com/p/e3fe7452368e
7.绘制角图片:
- (void)drawImageForImageView:(UIImageView *)imageView
{
UIGraphicsBeginImageContext(imageView.bounds.size);
//获取上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//设置线条宽度
CGContextSetLineWidth(context, 6.0f);
//设置颜色
CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
//路径
CGContextBeginPath(context);
//设置起点坐标
CGContextMoveToPoint(context, 0, imageView.bounds.size.height);
//设置下一个点坐标
CGContextAddLineToPoint(context, 0, 0);
CGContextAddLineToPoint(context, imageView.bounds.size.width, 0);
//渲染,连接起点和下一个坐标点
CGContextStrokePath(context);
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
8.绘制线图片:
- (void)drawLineForImageView:(UIImageView *)imageView
{
CGSize size = imageView.bounds.size;
UIGraphicsBeginImageContext(size);
//获取上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//创建一个颜色空间
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//设置开始颜色
const CGFloat *startColorComponents = CGColorGetComponents([[UIColor greenColor] CGColor]);
//设置结束颜色
const CGFloat *endColorComponents = CGColorGetComponents([[UIColor whiteColor] CGColor]);
//颜色分量的强度值数组
CGFloat components[8] = {startColorComponents[0], startColorComponents[1], startColorComponents[2], startColorComponents[3], endColorComponents[0], endColorComponents[1], endColorComponents[2], endColorComponents[3]
};
//渐变系数数组
CGFloat locations[] = {0.0, 1.0};
//创建渐变对象
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
//绘制渐变
CGContextDrawRadialGradient(context, gradient, CGPointMake(size.width * 0.5, size.height * 0.5), size.width * 0.25, CGPointMake(size.width * 0.5, size.height * 0.5), size.width * 0.5, kCGGradientDrawsBeforeStartLocation);
//释放
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
9.IP地址正则:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]):\\d{0,5}$"];
if (![predicate evaluateWithObject:setipTextField.text ?: @""]) {
[HComFun showFaildMsg:@"请输入正确的ip地址和端口"];
return;
}