国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS學習筆記之遠程推送、靜默推送與自定義消息推送

2024-09-11 00:40:44
字體:
來源:轉載
供稿:網友

遠程推送時 , 應用可能處于下列三種狀態:

     (1) . 應用開啟時 , 應用在前臺

    (2) . 應用開啟時 , 應用在后臺

    (3) . 應用未啟動(應用被殺死)

從蘋果APNS服務器遠程推送時:

1 . 如果應用處于 (1) 狀態 , 則不會發出聲音 , 會直接調用appDelegate的代理方法didReceiveRemoteNotification,此時如果想收到類似系統的彈窗提示,則需要自定義彈窗,提示音,振動(彈窗可以參考 : ForeNotification  (本地下載))

AudioServicesPlaySystemSound(1007);//系統提示音AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//震動

2 . 如果應用處于 (2) 狀態 , 則會發出提示音, 點擊推送消息 , 則會調用appDelegate的代理方法didReceiveRemoteNotification

3 . 如果應用處于 (3) 狀態,則會發出提示音 , 點擊推送消息 , 則會開啟應用 , 在下面這個方法中會帶上launchOptions這個參數,如果實現了application:didReceiveRemoteNotification:fetchCompletionHandler:這個方法,則會調用這個方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotification) { //自定義的BOOL值,用來標記是從通知啟動的應用 self.isLaunchedByNotification = YES; }else{ } [self checkIsLaunchedByNotification]; return YES;}

收到遠程推送后 , 可以跳轉到消息界面 :

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSDictionary *aps = [userInfo valueForKey:@"aps"]; NSDictionary *alert = [aps valueForKey:@"alert"]; NSString * body = alert[@"body"]; if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { //處于前臺時  [EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":[NSString stringWithFormat:@"%@",body]}} soundID:1312];  }else{  //處于后臺時  [self gotoMessageVC]; }}#pragma mark - 檢測是否從通知欄啟動得應用- (void)checkIsLaunchedByNotification{  if (self.isLaunchedByNotification) {  [self gotoMessageVC];  }}#pragma mark - 點擊了通知菜單(當應用在前臺時,收到推送,點擊了自定義的彈窗,調用的方法)- (void)clickBannerView:(NSNotification *)notification{  NSDictionary * dict = notification.object;  [self gotoMessageVC];}#pragma mark - 跳轉到消息界面(點擊通知菜單/點擊通知欄啟動應用時)- (void)gotoMessageVC{  if([self.window.rootViewController isEqual:self.tabBarController]){  if([self.tabBarController.selectedViewController isKindOfClass:[UINavigationController class]]){  UINavigationController * nav = self.tabBarController.selectedViewController;    if (![nav.topViewController isKindOfClass:[MessagesViewController class]]) {    MessagesViewController *messageVC = [[MessagesViewController alloc] init];    messageVC.hidesBottomBarWhenPushed = YES;    [nav.visibleViewController.navigationController pushViewController:messageVC animated:YES];  } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 二连浩特市| 清水河县| 永仁县| 海门市| 长春市| 新宾| 中西区| 白玉县| 博白县| 乐都县| 房产| 南京市| 焦作市| 磐石市| 灌云县| 克拉玛依市| 南召县| 南木林县| 洛南县| 安阳县| 汉沽区| 宜黄县| 饶平县| 库车县| 梨树县| 克东县| 永州市| 祥云县| 武冈市| 长寿区| 崇文区| 余庆县| 开平市| 隆化县| 门头沟区| 兖州市| 芷江| 仲巴县| 玉树县| 吉木萨尔县| 习水县|