- (UIImage*) imageWithUIView:(UIView*) view{
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef currnetContext = UIGraphicsGetCurrentContext();
//[view.layer drawInContext:currnetContext];
[view.layer renderInContext:currnetContext];
// 从当前context中创建一个改变大小后的图片
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
return image;
}
// 如果含有中文,将url的中文转码
NSString *string = value;
BOOL containChinese = NO;
for(int i=0; i< [string length];i++){
int a = [string characterAtIndex:i];
if( a > 0x4e00 && a < 0x9fff) {
containChinese = YES;
break;
}
}
if (containChinese) {
// 含中文的情况
self.url = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
} else {
// 不含中文
self.url = string;
}
在Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
if (flags & kSCNetworkReachabilityFlagsIsWWAN) {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
NSString *currentRadioAccessTechnology = info.currentRadioAccessTechnology;
if (currentRadioAccessTechnology) {
if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
return kReachableVia4G;
} else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge] || [currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
return kReachableVia2G;
} else {
return kReachableVia3G;
}
}
}
if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) {
if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) {
return kReachableVia2G;
}
return kReachableVia3G;
}
return kReachableViaWWAN;
}
网友评论