1:FCUUID获取设备标识的运用
a:作者 githun地址 https://github.com/fabiocaccamo/FCUUID
因为里面还用到作者的另外一个类UICKeyChainStore地址:https://github.com/kishikawakatsumi/UICKeyChainStore
b:在项目中添加 Security.framework
c:导入头文件 #import “FCUUID.h"
// 每次运行应用都会变
+(NSString *)uuid;
//changes each time (no persistent), but allows to keep in memory more temporary uuids
+(NSString *)uuidForKey:(id<NSCopying>)key;
// 每次运行应用都会变
+(NSString *)uuidForSession;
// 重新安装的时候会变
+(NSString *)uuidForInstallation;
// 卸载后重装会变
+(NSString *)uuidForVendor;
// 抹掉iPhone的时候才会变,适合做唯一标识
+(NSString *)uuidForDevice;
2:在图片增加一个外围的白色边框
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
//UIGraphicsBeginImageContext(image.size);
//解决失真 模糊的问题
UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef context =UIGraphicsGetCurrentContext();
//圆的边框宽度为2,颜色为红色
CGContextSetLineWidth(context,2);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset *2.0f, image.size.height - inset *2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
//在圆区域内画出image原图
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
//生成新的image
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
注意:如果使用UIGraphicsBeginImageContext(image.size);会导致图片有点失真模糊,可以采用 UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);还有如果在视图上进行画圆,只有在视图没有其它盖住时才看得到,比如如果有个背景图片,那么它就没盖住了;
3:在普通视图控制器包一个UINavigation
#pragma mark 添加导航栏
-(void)addNavigationBar{
//创建一个导航栏
UINavigationBar *navigationBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44+20)];
//navigationBar.tintColor=[UIColor whiteColor];
[self.view addSubview:navigationBar];
//创建导航控件内容
UINavigationItem *navigationItem=[[UINavigationItem alloc]initWithTitle:@"Web Chat"];
//左侧添加登录按钮
UIBarButtonItem *loginButton=[[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStyleDone target:self action:@selector(login)];
navigationItem.leftBarButtonItem=loginButton;
//添加内容到导航栏
[navigationBar pushNavigationItem:navigationItem animated:NO];
}
4:系统自带定位坐标转为城市名
//系统自带定位
[[MPLocationManager shareInstance] startSystemLocationWithRes:^(CLLocation *loction, NSError *error) {
if (!error) {
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:loction completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (placemarks.count>0) {
CLPlacemark *placemark=[placemarks objectAtIndex:0];
//获取城市
NSString *city = placemark.locality;
if (!city) {
//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
city = placemark.administrativeArea;
}
//有差异才改变
if(![BBUserDefault.LocationCity isEqualToString:city])
{
BBUserDefault.LocationCity=city;
}
NSLog(@"当前城市:[%@]",city);
}
}];