APPDELEGATE
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// 如果应用程序在前台,将应用程序图标上红色徽标中数字设为0
application.applicationIconBadgeNumber = 0;
// 使用UIAlertView显示本地通知的信息
[[[UIAlertView alloc] initWithTitle:@"收到通知"
message:notification.alertBody
delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show];
}
VIEWCONTROLLER 拖拽开关按钮控件
@interface ViewController ()
{
UIApplication * app;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
app = [UIApplication sharedApplication];
}
- (IBAction)swich:(id)sender {
UISwitch * swich = (UISwitch *)sender;
if(swich.on)
{
if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
//创建一个本地通知
UILocalNotification * notification = [[UILocalNotification alloc]init];
//设置一个通知触发时间
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//设置一个通知时区
notification.timeZone = [NSTimeZone defaultTimeZone];
// 设置通知的重复发送的事件间隔
notification.repeatInterval = kCFCalendarUnitHour;
//通知标题
notification.alertTitle=@"洪恩英语就是牛逼";
// 设置当设备处于锁屏状态时,显示通知的警告框下方的title
notification.alertAction = @"打开";
// 设置通知是否可显示Action
notification.hasAction = YES;
// 设置通知内容
notification.alertBody = @"洪恩英语NB !";
// 设置显示在应用程序上红色徽标中的数字
notification.applicationIconBadgeNumber = 1;
// 设置userinfo,用于携带额外的附加信息。
NSDictionary *info = @{@"bys": @"key"};
notification.userInfo = info;
// 调度通知
[app scheduleLocalNotification:notification]; // ①
}
else
{
NSArray * localArray = [app scheduledLocalNotifications];
if(localArray)
{
for (UILocalNotification * noti in localArray)
{
NSDictionary * dic = noti.userInfo;
if(dic)
{
NSString * inkey = [dic objectForKey:@"key"];
if([inkey isEqualToString:@"bys"])
{
[app cancelLocalNotification:noti];
}
}
}
}
}
}
————————————正则表达式————————————
{
UITextField * text;
UIButton * btn;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.title = @"物流管理系统";
self.view.backgroundColor= [UIColor whiteColor];
text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 45)];
text.placeholder =@"请输入手机号码";
[self.view addSubview:text];
btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 200, 45)];
[btn setTitle:@"验证" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor blueColor];
[btn addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)press{
NSString *checkString = text.text;
// 1.创建正则表达式,
//NSString *pattern = @"^\\d{14}[[0-9],0-9xX]$";
NSString *pattern = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";
// 1.1将正则表达式设置为OC规则
NSPredicate * preURL =[NSPredicate predicateWithFormat:@"self matches%@",pattern ];
bool b1 = [preURL evaluateWithObject:checkString];
if (b1) {
NSLog(@"手机号验证正确");
ViewController * view = [[ViewController alloc]init];
[self.navigationController pushViewController:view animated:YES];
}else{
NSLog(@"手机号验证不正确");
}
}
网友评论