这里会归纳一些在Objective-C开发中常用的代码 代码会慢慢增多 =)
生成一定范围的随机数
Objective-C
-(float)RandomFloatStart:(float)a end:(float)b { srand((unsigned)time(0)); float random = ((float) rand()) / (float) RAND_MAX; float diff = b - a; float r = random * diff; return a + r; }
验证邮箱是否合法
- (BOOL) validEmail:(NSString*) emailString { if([emailString length]==0){ return NO; } NSString *regExPattern = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:regExPattern options:NSRegularExpressionCaseInsensitive error:nil]; NSUInteger regExMatches = [regEx numberOfMatchesInString:emailString options:0 range:NSMakeRange(0, [emailString length])]; NSLog(@"%i", regExMatches); if (regExMatches == 0) { return NO; } else { return YES; } }
判断手机是否越狱
+(BOOL)isJailbroken { NSString *filePath = @"/Applications/Cydia.app"; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { return YES; } else { return NO; } }
or
+(BOOL)isJailbroken { FILE *f = fopen("/bin/bash", "r"); BOOL isbash = NO; if (f != NULL) { //Device is jailbroken isbash = YES; } fclose(f); }
时间: 2024-11-11 08:02:47