iOS 开发中的一些小功能

1.本地通知,应用按HOME退出到后台,10秒后本地发起通知。(类似于push通知)

UILocalNotification *notification=[[UILocalNotification alloc] init]; 

if (notification!=nil) { 

NSLog(@">> support local notification"); 

NSDate *now=[NSDate new]; 

notification.fireDate=[now addTimeInterval:10]; 

notification.timeZone=[NSTimeZone defaultTimeZone]; 

notification.alertBody=@"该去吃晚饭了!"; 

[[UIApplication sharedApplication].scheduleLocalNotification:notification];

}

2.判断邮箱输入是否正确。

- (BOOL) validateEmail: (NSString *) candidate {

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:candidate];

}

3.如何保存当前视图到相册。

#import <QuartzCore/QuartzCore.h>

UIGraphicsBeginImageContext(currentView.bounds.size);     //currentView 当前的view

[currentView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

 

posted @ 2015-01-16 15:57  农夫三拳!  阅读(136)  评论(0编辑  收藏  举报