A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© vitanie 中级黑马   /  2015-3-2 19:02  /  3094 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

[code]+ (void)validateAppWithName:(NSString *)name
{
void (^GetDataFinishBlock) (NSData *data) = ^(NSData *data)
{
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *result = [dic objectForKey:@"result"];
if([result intValue] != 0)
return;

// NSLog(@"app result type: %@", [dic objectForKey:@"type"]);
if([[dic objectForKey:@"type"] intValue] == 1)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"当前版本即将不可用,请联系您的软件供应商" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else if([[dic objectForKey:@"type"] intValue] == 2)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"当前版本已不可用,请联系您的软件供应商" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alert show];

// 延迟5秒执行:
double delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// code to be executed on the main queue after delay
exit(0);
});
}

};

// 后台执行:
dispatch_async(dispatch_get_global_queue(0, 0), ^{

NSString *urlStr = [NSString stringWithFormat:@"http://121.199.61.107/AppValidate/findByName.action?name=%@", name];
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlStr]];
if(!data)
return;

// 主线程执行:
dispatch_async(dispatch_get_main_queue(), ^{
// something
GetDataFinishBlock(data);
});
});

}

#pragma mark - // 常用方法

+ (CGRect)getFrameFollowView:(UIView *)view withInterval:(float)interval isRight:(BOOL)is
{
CGRect rect;
if(is)
{
rect = CGRectMake(view.Right+interval, view.Top, view.Width, view.Height);
}
else
{
rect = CGRectMake(view.Left, view.Bottom+interval, view.Width, view.Height);
}
return rect;
}

// 获取一个Frame 在另一个View 的左面
+ (CGRect)followSomeViewRight:(UIView *)view
{
CGRect rect = CGRectMake(view.Right, view.Top, view.Width, view.Height);
return rect;
}

// 获取一个Frame 在另一个View 的下面
+ (CGRect)followSomeViewBottom:(UIView *)view
{
CGRect rect = CGRectMake(view.Left, view.Bottom, view.Width, view.Height);
return rect;
}

/**
判断某个点是否在 某个视图内
*/
+ (BOOL)point:(CGPoint)p isInView:(UIView *)view
{
return ((p.x > view.Left) && (p.x < view.Right) && (p.y > view.Top) && (p.y < view.Bottom));
}

#pragma mark - // 其它常用方法
// 获取当前语言
+ (NSString *)getCurrentLanguage
{
NSArray *languages = [NSLocale preferredLanguages];
NSString *currentLanguage = [languages objectAtIndex:0];
return currentLanguage;
}

+ (BOOL)openUrlStr:(NSString *)str
{
UIApplication *app = [UIApplication sharedApplication];
return [app openURL:[NSURL URLWithString:str]];
}

// 1. 返回当年月日
+ (NSString *)getDateStringFromNowDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
return dateStr;
}

//程序中使用的,将日期显示成 2011年4月4日 星期一
+ (NSString *) Date2StrV:(NSDate *)indate{

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]]; //setLocale 方法将其转为中文的日期表达
dateFormatter.dateFormat = @"yyyy '-' MM '-' dd ' ' EEEE";
NSString *tempstr = [dateFormatter stringFromDate:indate];
return tempstr;
}
//程序中使用的,将日期显示成 2011年4月4日
+ (NSString *) Date3StrV:(NSDate *)indate{

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]]; //setLocale 方法将其转为中文的日期表达
dateFormatter.dateFormat = @"yyyy '-' MM '-' dd";
NSString *tempstr = [dateFormatter stringFromDate:indate];
return tempstr;
}
+ (NSString *)dateFormatString_Type02
{
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat.dateFormat = @"yyyyMMddHHmmss";
NSString *time = [dateFormat stringFromDate:date];

return time;
}
+(NSString *)dateFormatString
{
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *time = [dateFormat stringFromDate:date];

return time;
}
//打开一个网址
+ (void) OpenUrl:(NSString *)inUrl
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:inUrl]];
}

// 2. 显示简单弹窗
+ (void)showAlertViewWithMessage:(NSString *)message
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}

// 3. 返回应用当前语言是否为中文
+ (BOOL)isChinese
{
NSString *language = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
return [language isEqualToString:@"zh-Hans"] ? YES : NO;
}

// 4. 每次进入应用判断有无 过期 标识
+ (BOOL)judgeTimeOver
{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIWindow *window = app.window;
// 每次进入应用判断有无 过期 标识
if([[NSUserDefaults standardUserDefaults] objectForKey:@"overdue"])
{
UILabel *label = [UILabel LabelTextCenterWithFrame:CGRectMake(10, 100, 300, 200) text:@"当前软件版本较低,请联系您的软件供应商" textColor:kBlackColor font:FontSize(25) textAlignment:1];
//自动折行设置
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
[window addSubview:label];
return YES;
}

// 设定软件使用时限 // 到 2014年 01月 01日 + 天数 * n // 2014-09-01 00:00:00 +0000
NSDate *lastDate = [NSDate dateWithTimeIntervalSince1970:
(3600*24*365*44+3600*24*10+3600*16+3600*8) + 3600*24 * 243 ];
NSLog(@"最后时间 : %@",lastDate);

NSDate *today = [NSDate date];
float interval = [today timeIntervalSinceDate:lastDate];
if(interval > 0)
{
// 一时过期 则写入一个过期标识 并进入另一个提示页面
[[NSUserDefaults standardUserDefaults] setObject:@"overdue" forKey:@"overdue"];
[[NSUserDefaults standardUserDefaults] synchronize];
UILabel *label = [UILabel LabelTextCenterWithFrame:CGRectMake(10, 100, 300, 200) text:@"当前软件版本较低,请联系您的软件供应商" textColor:kBlackColor font:FontSize(25) textAlignment:1];
//自动折行设置
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
[window addSubview:label];
return YES;
}
return NO;
}

+ (NSString *)getVersion
{
NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
NSString *Version = [dic objectForKey:@"CFBundleVersion"];
// NSLog(@"%@", Version);
return Version;

/*
{
BuildMachineOSBuild = 13E28;
CFBundleDevelopmentRegion = en;
CFBundleDisplayName = ShouKang;
CFBundleExecutable = ShouKang;
CFBundleIdentifier = "rongeApp.com.cn.sk";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleInfoPlistURL = "Info.plist";
CFBundleName = ShouKang;
CFBundleNumericVersion = 16809984;
CFBundlePackageType = APPL;
CFBundleResourceSpecification = "ResourceRules.plist";
CFBundleShortVersionString = "1.0";
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneOS
);
CFBundleURLTypes = (
{
CFBundleURLName = "";
CFBundleURLSchemes = (
ShouKang
);
}
);
CFBundleVersion = "1.0";
DTCompiler = "com.apple.compilers.llvm.clang.1_0";
DTPlatformBuild = 11B508;
DTPlatformName = iphoneos;
DTPlatformVersion = "7.0";
DTSDKBuild = 11B508;
DTSDKName = "iphoneos7.0";
DTXcode = 0502;
DTXcodeBuild = 5A3005;
LSRequiresIPhoneOS = 1;
MinimumOSVersion = "6.1";
UIBackgroundModes = (
voip,
audio
);
UIDeviceFamily = (
1
);
UILaunchImageFile = LaunchImage;
UILaunchImages = (
{
UILaunchImageMinimumOSVersion = "7.0";
UILaunchImageName = "LaunchImage-700-568h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{320, 568}";
}
);
UIRequiredDeviceCapabilities = (
microphone,
wifi
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait
);
UIViewControllerBasedStatusBarAppearance = 0;
}
*/
}

#pragma mark - // 手机号 邮箱 车牌号 身份证 验证方法

/*邮箱验证 MODIFIED BY HELENSONG*/
+ (BOOL)isValidateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}

/*手机号码验证 MODIFIED BY HELENSONG*/
+ (BOOL) isValidateMobile:(NSString *)mobile
{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
// NSLog(@"phoneTest is %@",phoneTest);
return [phoneTest evaluateWithObject:mobile];
}

/*车牌号验证 MODIFIED BY HELENSONG*/
+ (BOOL) isValidateCarNumber:(NSString *)carNumber
{
NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$";
NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
NSLog(@"carTest is %@",carTest);
return [carTest evaluateWithObject:carNumber];
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马