本地消息推送

NSString *yourXMLDate = @"08:00" ;
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"HH:mm"];
    NSDate *inputDate = [inputFormatter dateFromString:yourXMLDate];
//創建一個本地推送
    UILocalNotification *noti = [[[UILocalNotification alloc] init] autorelease];
    if (noti) {      
        //設置推送時間
        noti.fireDate = inputDate;      
        //設置時區  
        noti.timeZone = [NSTimeZone defaultTimeZone];    
        //設置重複間隔  
        noti.repeatInterval = NSWeekdayCalendarUnit;  
        //推送聲音  
        noti.soundName = UILocalNotificationDefaultSoundName;  
        //內容  
        noti.alertBody = @"推送內容";  
        //顯示在icon上的紅色圈中的數子
        noti.applicationIconBadgeNumber = 1;
        //設置userinfo 方便在之後需要撤銷的時候使用
        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
        noti.userInfo = infoDic;      
        //添加推送到uiapplication        
        UIApplication *app = [UIApplication sharedApplication];
        [app scheduleLocalNotification:noti];  

    }       
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章