本地推送

viewController中

-(void)openNotification
{
    if (ctm == 0) {
        return;
    }
    UILocalNotification *notification=[[UILocalNotification alloc] init];
    if (notification!=nil)
    {
        NSDate *now=[NSDate new];
        notification.fireDate=[now dateByAddingTimeInterval:ctm*600];
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.applicationIconBadgeNumber = 1;
        notification.alertBody = [NSString stringWithFormat:AlertBody];
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSString stringWithFormat:@"tab2"], @"key1", nil];
        [notification setUserInfo:dict];
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
    
    //    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    //[swt setOn:YES animated:NO];
    
}
-(void)closeNotification
{
    UILocalNotification *not;
    for (UILocalNotification *local in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
        if ([[local.userInfo objectForKey:@"key1"] isEqualToString:@"tab2"]) {
            not = local;
        }
        
    }
    if (not) {
        [[UIApplication sharedApplication] cancelLocalNotification:not];
    }
    // [swt setOn:NO animated:NO];
    
}

appDelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
      application.applicationIconBadgeNumber = 0;
    if (![[NSUserDefaults standardUserDefaults] objectForKey:@"2ndState"]) {
        NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"60",@"max",@"0",@"now",@"0",@"state",nil];
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"2ndState"];
    }
    return YES;
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    if (notification) {
        [[UIApplication sharedApplication]cancelLocalNotification:notification];
    }
    UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"通知" message:notification.alertBody  delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    FourthViewController *viewController = [FourthViewController sharedInstance];
    
    [viewController.swt setOn:NO animated:YES];
    [viewController.sld setEnabled:NO];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"2ndState"]];
    
    [dic setObject:[NSString stringWithFormat:@"%d",(int)[viewController.swt isOn]] forKey:@"state"];
    
    [[NSUserDefaults standardUserDefaults] setObject:(NSDictionary*)dic forKey:@"2ndState"];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
      application.applicationIconBadgeNumber = 0;
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值