标签:
1.iOS9新特性:Bitcode
当运行之前的项目报错时,我们可以在”Build Settings”->”Enable Bitcode”中设置属性为NO
2.获取设备名字
[Device machineName]
3.获取沙盒Documents路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0];
4.发短信方法
4.1openURL
[[UIApplication sharedApplication] openURL:@"sms:12345678"];
4.2MFMessageComposeViewController
首先在程序中导入MessageUI.framework。import头文件:#import "DeviceDetection.h"
然后在代码中使用下面的语句来调用短信发送窗口,并指定号码和短信内容:
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; controller.title = @"短信房源"; controller.body = HouseInfo; controller.recipients = nil; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil];
5.复制内容到剪切板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = ResponseObj;
6。iOS字符创中去除特殊字符串
NSInteger leftLength=[[leftStr stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length;
7.NSCharacterSet 简单用法
NSMutableCharacterSet *base = [NSMutableCharacterSet lowercaseLetterCharacterSet]; //字母 NSCharacterSet *decimalDigit = [NSCharacterSet decimalDigitCharacterSet]; //十进制数字 [base formUnionWithCharacterSet:decimalDigit]; //字母加十进制 NSString *string = @"ax@d5s#@sfn$5`SF$$%x^(#e{]e"; //用上面的base隔开string然后组成一个数组,然后通过componentsJoinedByString,来连接成一个字符串 NSLog(@"%@",[[string componentsSeparatedByCharactersInSet:base] componentsJoinedByString:@"-"]); [base invert]; //非 字母加十进制 NSLog(@"%@",[[string componentsSeparatedByCharactersInSet:base] componentsJoinedByString:@"-"]); 答应结果: ax@d-s#@sfn$-`SF$$%x^(#e{]e ----5-------5--------------
8.从系统选择多张图片
先导入库ELCImagePicker(第三方)
//从照片库 if ([self shouldImage]) { ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker]; elcPicker.maximumImagesCount = 16-[images_ numberOfPhotos]; elcPicker.returnsOriginalImage = NO; elcPicker.imagePickerDelegate = self; [self presentViewController:elcPicker animated:YES completion:nil]; }else { UIAlertView *al=[[UIAlertView alloc]initWithTitle:@"权限受限" message:@"设置-手机梵讯-隐私" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [al show]; }
#pragma mark ELCImagePickerController delegate -(void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info { NSString *imagePathDir; BOOL isSuccess = NO; for (NSDictionary *dict in info) { UIImage* img = [dict objectForKey:UIImagePickerControllerOriginalImage]; imagePathDir = [[Util getHouseDirCurrentDateType] stringByReplacingOccurrencesOfString:@"_city_" withString:[YlwSingleMode shareDataModle].CityPinyin]; //需要准备的数据 NSString *PKHouseImageLite = [Util GetUUIDLite]; NSString *PKHouseImage = [Util convertGuidSqlserverFromSqlite:PKHouseImageLite isClean:YES]; NSString *imgType = @".jpg"; CGSize sizeImageBig = [self getImageSize:img.size targetSize:CGSizeMake(600, 450)]; CGSize sizeImageSmall = [self getImageSize:img.size targetSize:CGSizeMake(200, 150)]; CGSize sizeImageIndex = [self getImageSize:img.size targetSize:CGSizeMake(80, 60)]; UIImage *imgBig = [self reSizeImage:img toSize:sizeImageBig]; UIImage *imgSmall = [self reSizeImage:img toSize:sizeImageSmall]; UIImage *imgIndex = [self reSizeImage:img toSize:sizeImageIndex]; imagePathDir=[imagePathDir stringByReplacingOccurrencesOfString:@"house/" withString:@"House/"]; NSString *imagePathBig = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_big.jpg",PKHouseImage]]; NSString *imagePathSmall = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_small.jpg",PKHouseImage]]; NSString *imagePathIndex = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_index.jpg",PKHouseImage]]; NSData *imgBigData = UIImageJPEGRepresentation(imgBig, 0.3); NSData *imgSmallData = UIImageJPEGRepresentation(imgSmall, 0.3); NSData *imgIndexData = UIImageJPEGRepresentation(imgIndex, 0.3); NSInteger imgSize_Big = imgBigData.length; NSInteger imgSize_Small = imgSmallData.length; for (int i=0; i<3; i++) { [_houseImageCache storeImage:imgBig imageData:imgBigData forKey:imagePathBig toDisk:YES]; i++; [_houseImageCache storeImage:imgSmall imageData:imgSmallData forKey:imagePathSmall toDisk:YES]; i++; [_houseImageCache storeImage:imgIndex imageData:imgIndexData forKey:imagePathIndex toDisk:YES]; } isSuccess = [self saveHouseImagesWith:PKHouseImageLite ImgPath:imagePathDir ImgType:imgType ImgSizeBig:imgSize_Big ImgSizeSmaill:imgSize_Small]; [self houseimageNumber:nil]; } if (isSuccess) { [ProgressHUD showSuccess:@"添加成功"]; [picker dismissViewControllerAnimated:YES completion:nil]; [self reloadSubviews]; } }
-(void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; NSString *imagePathDir; BOOL isSuccess = NO; if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) { UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); imagePathDir = [[Util getHouseDirCurrentDateType] stringByReplacingOccurrencesOfString:@"_city_" withString:[YlwSingleMode shareDataModle].CityPinyin]; //需要准备的数据 NSString *PKHouseImageLite = [Util GetUUIDLite]; NSString *PKHouseImage = [Util convertGuidSqlserverFromSqlite:PKHouseImageLite isClean:YES]; NSString *imgType = @".jpg"; CGSize sizeImageBig = [self getImageSize:img.size targetSize:CGSizeMake(600, 450)]; CGSize sizeImageSmall = [self getImageSize:img.size targetSize:CGSizeMake(200, 150)]; CGSize sizeImageIndex = [self getImageSize:img.size targetSize:CGSizeMake(80, 60)]; UIImage *imgBig = [self reSizeImage:img toSize:sizeImageBig]; UIImage *imgSmall = [self reSizeImage:img toSize:sizeImageSmall]; UIImage *imgIndex = [self reSizeImage:img toSize:sizeImageIndex]; imagePathDir=[imagePathDir stringByReplacingOccurrencesOfString:@"house/" withString:@"House/"]; NSString *imagePathBig = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_big.jpg",PKHouseImage]]; NSString *imagePathSmall = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_small.jpg",PKHouseImage]]; NSString *imagePathIndex = [imagePathDir stringByAppendingPathComponent:[NSString stringWithFormat:@"house_%@_index.jpg",PKHouseImage]]; NSData *imgBigData = UIImageJPEGRepresentation(imgBig, 0.3); NSData *imgSmallData = UIImageJPEGRepresentation(imgSmall, 0.3); NSData *imgIndexData = UIImageJPEGRepresentation(imgIndex, 0.3); NSInteger imgSize_Big = imgBigData.length; NSInteger imgSize_Small = imgSmallData.length; for (int i=0; i<3; i++) { [_houseImageCache storeImage:imgBig imageData:imgBigData forKey:imagePathBig toDisk:YES]; i++; [_houseImageCache storeImage:imgSmall imageData:imgSmallData forKey:imagePathSmall toDisk:YES]; i++; [_houseImageCache storeImage:imgIndex imageData:imgIndexData forKey:imagePathIndex toDisk:YES]; } isSuccess = [self saveHouseImagesWith:PKHouseImageLite ImgPath:imagePathDir ImgType:imgType ImgSizeBig:imgSize_Big ImgSizeSmaill:imgSize_Small]; [self houseimageNumber:nil]; if (isSuccess) { [ProgressHUD showSuccess:@"添加成功"]; [picker dismissViewControllerAnimated:YES completion:nil]; [self reloadSubviews]; } } }
-(void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{ if (!error) { NSLog(@"保存有误"); } else { NSLog(@"错误提示%@", error); } } -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:nil]; }
9.判断是否支持拍照和相册
-(BOOL)shouldPhoto { BOOL agree=NO; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized||authStatus == AVAuthorizationStatusNotDetermined) { agree=YES; }else { agree=NO; } return agree; } -(BOOL)shouldImage { BOOL agree=NO; ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus]; if(author == ALAuthorizationStatusAuthorized||author == ALAuthorizationStatusNotDetermined) { agree=YES; }else { agree=NO; } return agree; }
10.上传图片
+(void)httpUploadHeadImage:(NSString *)Actio WithParam:(NSDictionary *)param success:(void(^)(id ResponseObject))Success Failure:(void (^)(id ResponseObject))Failure { NSMutableDictionary *mDict = [NSMutableDictionary dictionary]; if (param!=nil) { [mDict setDictionary:param]; } AFHTTPRequestOperationManager * manager =[AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFHTTPRequestSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager POST:Actio parameters:NULL constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFormData:[[NSString stringWithString:[mDict objectForKey:@"PKUser"]] dataUsingEncoding:NSUTF8StringEncoding] name:@"PKUser"]; [formData appendPartWithFormData:[[NSString stringWithString:[mDict objectForKey:@"relPath"]] dataUsingEncoding:NSUTF8StringEncoding] name:@"relPath"]; NSData * data=[NSData dataWithContentsOfFile:[mDict objectForKey:@"HeadBig"]]; [formData appendPartWithFileData:data name:@"big" fileName:[mDict objectForKey:@"HadebigName"] mimeType: @"Image/jpep"]; NSData * data1=[NSData dataWithContentsOfFile:[mDict objectForKey:@"Headsmall"]]; [formData appendPartWithFileData:data1 name:@"small" fileName:[mDict objectForKey:@"HadesmallName"] mimeType: @"Image/png"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSData * responseData = responseObject; NSString * responseStr = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; Success(responseStr); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; }
标签:
原文地址:http://www.cnblogs.com/liaods/p/4832673.html