本地推送的實現(xiàn)

本地推送(主要用于耗時操作,當操作完成之后可以通知給用戶)

步驟如下:

1.在app delegate? didFinishLaunchingWithOptions方法中進行推送設(shè)置

推送設(shè)置(iOS8.0以后設(shè)置方法發(fā)生改變)

//版本適配問題

if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)//當前使用設(shè)備

{

//采取8.0以上的設(shè)置

/**

*? @param UIUserNotificationType 推動通知的類型(聲音/文字/標示(徽章))

*? @param categories 額外設(shè)置(設(shè)置額外按鈕)

*/

UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];

//讓當前程序接收/注冊推送通知設(shè)置

[application registerUserNotificationSettings:settings];

//詢問用戶是否允許

[application registerForRemoteNotifications];

}

2.開始推送

UILocalNotification * noti = [[UILocalNotification alloc]init];

if (noti) {

//設(shè)置推送通知

//通知推送事件

//開啟事件為當前時間后10秒

noti.fireDate = [[NSDate date] dateByAddingTimeInterval:10];

//重復(fù)次數(shù)

//不重復(fù)

noti.repeatInterval = 0;

//設(shè)置推送時區(qū)

noti.timeZone = [NSTimeZone defaultTimeZone];

//增加圖標標示

noti.applicationIconBadgeNumber = 1;

//設(shè)置推送聲音 音頻聲音格式要為蘋果原生支持的

noti.soundName = UILocalNotificationDefaultSoundName;

//推送內(nèi)容

noti.alertBody = @"ajdfjkjljhb";

//設(shè)置推送的攜帶詳情,例如為某影片播放網(wǎng)址

noti.userInfo = @{@"URL":@""};

//執(zhí)行推送

[[UIApplication sharedApplication] scheduleLocalNotification:noti];

}

注:通過推送進入App時會調(diào)用的方法

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

{

NSLog(@"通過推送進入APP");

NSDictionary * us = notification.userInfo;

NSLog(@"URL為:%@",us[@"URL"]);

//執(zhí)行跳轉(zhuǎn)

[self.window.rootViewController presentViewController:[[PlayViewController alloc]init] animated:YES completion:nil];

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 推送通知 注意:這里說的推送通知跟NSNotification有所區(qū)別 NSNotification是抽象的,不可...
    iOS開發(fā)攻城獅閱讀 4,419評論 1 13
  • 概述 在多數(shù)移動應(yīng)用中任何時候都只能有一個應(yīng)用程序處于活躍狀態(tài),如果其他應(yīng)用此刻發(fā)生了一些用戶感興趣的那么通過通知...
    莫離_焱閱讀 6,719評論 1 8
  • 極光推送: 1.JPush當前版本是1.8.2,其SDK的開發(fā)除了正常的功能完善和擴展外也緊隨蘋果官方的步伐,SD...
    Isspace閱讀 6,884評論 10 16
  • 推送通知注意:這里說的推送通知跟NSNotification有所區(qū)別NSNotification是抽象的,不可見的...
    醉葉惜秋閱讀 1,618評論 0 3
  • 在簡單項目中,有使用到apns推送服務(wù),許多文章有涉及到卻沒有講清楚。最近做福路通項目,有使用到,做一個總結(jié)。 推...
    天空的守望者閱讀 974評論 0 3

友情鏈接更多精彩內(nèi)容