APPDELEGATE
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// 如果應(yīng)用程序在前臺(tái)粘我,將應(yīng)用程序圖標(biāo)上紅色徽標(biāo)中數(shù)字設(shè)為0
application.applicationIconBadgeNumber = 0;
// 使用UIAlertView顯示本地通知的信息
[[[UIAlertView alloc] initWithTitle:@"收到通知"
message:notification.alertBody
delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil] show];
}
VIEWCONTROLLER ? ? ? 拖拽開關(guān)按鈕控件
@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]];
}
//創(chuàng)建一個(gè)本地通知
UILocalNotification * notification = [[UILocalNotification alloc]init];
//設(shè)置一個(gè)通知觸發(fā)時(shí)間
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//設(shè)置一個(gè)通知時(shí)區(qū)
notification.timeZone = [NSTimeZone defaultTimeZone];
// 設(shè)置通知的重復(fù)發(fā)送的事件間隔
notification.repeatInterval = kCFCalendarUnitHour;
//通知標(biāo)題
notification.alertTitle=@"洪恩英語就是牛逼";
// 設(shè)置當(dāng)設(shè)備處于鎖屏狀態(tài)時(shí)跌穗,顯示通知的警告框下方的title
notification.alertAction = @"打開";
// 設(shè)置通知是否可顯示Action
notification.hasAction = YES;
// 設(shè)置通知內(nèi)容
notification.alertBody = @"洪恩英語NB !";
// 設(shè)置顯示在應(yīng)用程序上紅色徽標(biāo)中的數(shù)字
notification.applicationIconBadgeNumber = 1;
// 設(shè)置userinfo,用于攜帶額外的附加信息绊汹。
NSDictionary *info = @{@"bys": @"key"};
notification.userInfo = info;
// 調(diào)度通知
[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];
}
}
}
}
}
}
————————————正則表達(dá)式————————————
{
UITextField * text;
UIButton * btn;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.title = @"物流管理系統(tǒng)";
self.view.backgroundColor= [UIColor whiteColor];
text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 45)];
text.placeholder =@"請(qǐng)輸入手機(jī)號(hào)碼";
[self.view addSubview:text];
btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 200, 45)];
[btn setTitle:@"驗(yàn)證" 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.創(chuàng)建正則表達(dá)式,
//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將正則表達(dá)式設(shè)置為OC規(guī)則
NSPredicate * preURL =[NSPredicate predicateWithFormat:@"self matches%@",pattern ];
bool b1 = [preURL evaluateWithObject:checkString];
if (b1) {
NSLog(@"手機(jī)號(hào)驗(yàn)證正確");
ViewController * view = [[ViewController alloc]init];
[self.navigationController pushViewController:view animated:YES];
}else{
NSLog(@"手機(jī)號(hào)驗(yàn)證不正確");
}
}