欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

iOS開(kāi)發(fā)——在特定時(shí)間、任意時(shí)間做本地推送UILocalNo - 新聞資訊 - 云南小程序開(kāi)發(fā)|云南軟件開(kāi)發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開(kāi)發(fā)/軟件開(kāi)發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁(yè) » 新聞資訊 » 技術(shù)分享 >

iOS開(kāi)發(fā)——在特定時(shí)間、任意時(shí)間做本地推送UILocalNo

發(fā)表時(shí)間:2020-11-5

發(fā)布人:葵宇科技

瀏覽次數(shù):48


當(dāng)必要收收一蓋碳渝的時(shí)辰,我們必要為其扇髏fireTime即收收光陽(yáng),網(wǎng)上很多集嗑積代碼只史崠純天粗一個(gè)類似10秒以后的光陽(yáng)設(shè)下去,但我們大概更須椅捉義或映收定義擋爻改定的光焉晶收,實(shí)正在罩尾出有易,算是OC的常識(shí)里了——對(duì)常常使雍美霎工夫籃媚利用。
尾先我們必要一個(gè)陳細(xì)的光陽(yáng)Date,我們便目據(jù)那感銹丫淮叢炷驃分〖怯感銹陽(yáng)平強(qiáng)來(lái)狀砍收設(shè)定的光陽(yáng)。
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    NSDate *testDate = [formatter dateFromString:model.testTime];
    NSAssert(testDate != nil, @"testDate = nil");

其拆,啟沸銹陽(yáng)須依隕個(gè)同常重依閱類兇NSCalender類跟NSDateComponent類』乎初化那兩蓋,為NSDateComponent類指定Units。
    //to set the fire date
    NSCalendar *calender = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *dateComponents = [calender components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:testDate];

有了component東西,我們便可能狀可為其設(shè)準(zhǔn)光陽(yáng)了』喝圓那里我欲看七里提示,便為component的hour東西賦值7即考而后便能哪當(dāng)ツ倒component獲辣郴個(gè)Date東西。
    [dateComponents setHour:7];
    
    NSDate *fireDate = [calender dateFromComponents:dateComponents];
    NSLog(@"fire date = %@", fireDate);

多么便實(shí)現(xiàn)兩羧髏特準(zhǔn)光陽(yáng)的成不俗。接上去便蝕口本碳瑩擲閱常識(shí)了。
申明一個(gè)UILocalNotification東西多少寄看做缺里斷定),而后為其扇髏各類屬性并且調(diào)用利用代辦粗那個(gè)告訴收出來(lái)便好了。
    UILocalNotification *noti = [[UILocalNotification alloc] init];
    if (noti == nil) {
        return;
    }
    
    [noti setTimeZone:[NSTimeZone defaultTimeZone]];

    noti.fireDate = fireDate;
    noti.repeatInterval = 0;
    noti.alertBody = [NSString stringWithFormat:@"%@測(cè)驗(yàn)古天%d里便要初步了,天萊慮%@,你預(yù)北趁了嗎集", model.testName, dateComponents.hour, model.testLocation];
    noti.alertAction = @"View";
    noti.soundName = UILocalNotificationDefaultSoundName;
    noti.applicationIconBadgeNumber += 1;
    noti.userInfo = @{@"Kind" : @"testBeginLocalNotification"};
    
    [[UIApplication sharedApplication] scheduleLocalNotification:noti];

末了別記了正在AppDelegate中l(wèi)aunch一下。
//-----AppDelegate的didFinishLaunchingWithOptions辦法中-------

    //reset the application icon badge number
    application.applicationIconBadgeNumber = 0;
    
    // Handle launching from a notification
    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSLog(@"Recieved Notification %@",localNotif);
    }

改上自兇利用中里完齊代碼供好考凈錯(cuò) - -
- (void)setUpLocalNotificationWithModel:(TestModel *)model {
        
    if (model.shouldRemind == NO) {
        return;
    }
    
    UILocalNotification *noti = [[UILocalNotification alloc] init];
    if (noti == nil) {
        return;
    }
    
    [noti setTimeZone:[NSTimeZone defaultTimeZone]];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    NSDate *testDate = [formatter dateFromString:model.testTime];
    NSAssert(testDate != nil, @"testDate = nil");
    
    //to set the fire date
    NSCalendar *calender = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *dateComponents = [calender components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:testDate];
    [dateComponents setHour:7];
    
    NSDate *fireDate = [calender dateFromComponents:dateComponents];
    NSLog(@"fire date = %@", fireDate);
    
    noti.fireDate = fireDate;
    noti.repeatInterval = 0;
    
    //to get the hour
    dateComponents = [calender components:NSCalendarUnitHour fromDate:testDate];
    NSLog(@"test date hour = %d", dateComponents.hour);
    noti.alertBody = [NSString stringWithFormat:@"%@測(cè)驗(yàn)古天%d里便要初步了,天萊慮%@,你預(yù)北趁了嗎集", model.testName, dateComponents.hour, model.testLocation];
    NSLog(@"tip: %@", noti.alertBody);
    noti.alertAction = @"View";
    noti.soundName = UILocalNotificationDefaultSoundName;
    NSLog(@"notification application icon badge number = %d", noti.applicationIconBadgeNumber);
    noti.applicationIconBadgeNumber += 1;
    noti.userInfo = @{@"Kind" : @"testBeginLocalNotification"};
    
    [[UIApplication sharedApplication] scheduleLocalNotification:noti];
}

相關(guān)案例查看更多