成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開發基礎學習 在程序里設置Push

移動開發 iOS
本文介紹的是iPhone開發基礎學習 在程序里設置Push ,很詳細的為大家講解,我們先來看恩日。

iPhone開發基礎學習 在程序里設置Push是本文要介紹的內容,最近做項目有一個需求,要在程序得系統設置里進行push的設置。在網上搜了幾天資料沒找著啥。今天忽然心血來潮跟蹤系統注冊push時得代碼,居然發現有可行得解決方法,思路如下:

1、在iphone得framework里的UIApplication.h中有以下函數:

  1. @interface UIApplication (UIRemoteNotifications)  
  2. - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  
  3. - (void)unregisterForRemoteNotifications __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);       
  4. // calls -registerForRemoteNotificationTypes with UIRemoteNotificationTypeNone  
  5.  
  6. // returns the enabled types, also taking into account any systemwide settings; doesn't relate to connectivity  
  7. - (UIRemoteNotificationType)enabledRemoteNotificationTypes __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  
  8. @end 

2、首先可以用[[UIApplication sharedApplication] enabledRemoteNotificationTypes]獲取到允許得push推送類型。然后再調用registerForRemoteNotificationTypes進行修改。若要關閉程序得push服務,可調用unregisterForRemoteNotifications.

3、補充:以上想法以實現。補充部分代碼。settingsData為tableview的數據源數組

a、獲取系push設置,用于顯示給用戶

  1. //push設置  
  2.  
  3. NSMutableArray * pushOptions = [[NSMutableArray alloc] init];  
  4.  
  5. UIRemoteNotificationType notificationType = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];  
  6.  
  7.  
  8. NSMutableDictionary * soundNotice = [[NSMutableDictionary alloc] initWithObjectsAndKeys:  
  9.                                      @"聲音", @"name",  
  10.                                      @"0",   @"status",  
  11.                                      nil];  
  12. if (notificationType & UIRemoteNotificationTypeSound) {  
  13.     [soundNotice setValue:@"1" forKey:@"status"];  
  14. }          
  15. [pushOptions addObject:soundNotice];  
  16. [soundNotice release];  
  17.  
  18.  
  19. NSMutableDictionary * alertNotice = [[NSMutableDictionary alloc] initWithObjectsAndKeys:  
  20.                                      @"提醒", @"name",  
  21.                                      @"0",   @"status",  
  22.                                      nil];  
  23. if (notificationType & UIRemoteNotificationTypeAlert) {  
  24.     [alertNotice setValue:@"1" forKey:@"status"];  
  25. }          
  26. [pushOptions addObject:alertNotice];  
  27. [alertNotice release];  
  28.  
  29.  
  30. NSMutableDictionary * badgeNotice = [[NSMutableDictionary alloc] initWithObjectsAndKeys:  
  31.                                      @"標記", @"name",  
  32.                                      @"0",   @"status",  
  33.                                      nil];  
  34. if (notificationType & UIRemoteNotificationTypeBadge) {  
  35.     [badgeNotice setValue:@"1" forKey:@"status"];  
  36. }          
  37. [pushOptions addObject:badgeNotice];  
  38. [badgeNotice release];  
  39.  
  40.  
  41. NSDictionary * pushConfig = [[NSDictionary alloc] initWithObjectsAndKeys:  
  42.                               @"通知設置", @"groupName",  
  43.                               pushOptions,    @"data",  
  44.                               nil];  
  45. [self.settingsData addObject:pushConfig];  
  46. [pushOptions release];  
  47. [pushConfig release]; 

b、獲取用戶設置的數據放入pushdata,然后向系統提交設置

  1. NSArray * pushData = [[settingsData objectAtIndex:indexPath.section] objectForKey:@"data"];  
  2. NSInteger length = [pushData count];  
  3.  
  4. UIRemoteNotificationType myType = 0;  
  5.  
  6. for (NSInteger i =0; i< length; i++) {  
  7.     if ([[[pushData objectAtIndex:i] objectForKey:@"status"] intValue] ==1) {  
  8.         switch (i) {  
  9.             case 0:        myTypemyType = myType|UIRemoteNotificationTypeSound;    break;  
  10.             case 1:        myTypemyType = myType|UIRemoteNotificationTypeAlert;    break;  
  11.             case 2:        myTypemyType = myType|UIRemoteNotificationTypeBadge;    break;  
  12.             default:    break;  
  13.         }  
  14.     }  
  15. }  
  16.  
  17. if (myType != 0) {  
  18.     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myType];  
  19. }else {  
  20.     [[UIApplication sharedApplication] unregisterForRemoteNotifications];  

希望以上思路對有這方面需求得人有幫助。以上方案我暫未用于代碼實現。若有問題。請留言共同商討。

小結:iPhone開發基礎學習 在程序里設置Push的內容介紹完了,希望本文對你有所幫助1更多相關內容請參考編輯推薦。

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-07-18 14:33:32

2011-07-07 17:04:33

iPhone Action Objective-

2011-07-18 14:59:20

iPhone Objective-

2012-04-26 13:30:05

iPhoneApp Store發布程序

2011-07-25 16:47:01

HTTP Server PUSH

2011-08-10 16:44:56

iPhone代理設計模式

2011-07-25 18:07:29

iPhone Push Notificati

2011-08-08 10:10:14

iPhone開發 圖片 方法

2011-08-15 10:06:22

iPhone開發nib 文件

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-01 18:27:58

iPhone開發 UISearchBa

2011-07-18 09:35:29

iPhone 框架

2011-08-05 14:48:06

iPhone應用 異步隊列

2011-08-18 10:39:46

iPhone開發界面

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-03-08 16:57:13

proftpd

2011-07-20 17:10:05

iPhone iAd

2011-07-26 14:18:20

2011-08-18 10:02:47

iPhone SDKOpenFlow

2011-08-18 09:52:13

iPhone SDKUIPageContr
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 精品91久久 | 成人精品在线视频 | 国产专区免费 | 国产清纯白嫩初高生在线播放视频 | 免费一级黄 | 国产在线播放av | 蜜桃视频在线观看免费视频网站www | 免费在线观看黄网站 | 95国产精品| 国产精品www | 亚洲成人免费观看 | 久久精品在线播放 | 国产精品色一区二区三区 | 亚洲国产精品视频 | 97精品超碰一区二区三区 | 久久三区| 国产欧美一级二级三级在线视频 | 九九九久久国产免费 | 精品欧美久久 | 99热这里都是精品 | 精品毛片视频 | 视频一区二区三区中文字幕 | 国产一区二区三区四区 | 午夜男人的天堂 | 国产视频中文字幕 | 7777在线 | 懂色av一区二区三区在线播放 | 成人在线国产 | 国产一区久久久 | 亚洲毛片在线 | 亚洲美女天堂网 | 伊人网伊人网 | 99reav| 91精品久久久久久久 | 欧美一区二区三区在线观看 | 国产高清在线 | 国产激情综合五月久久 | 欧美精品在线一区二区三区 | 噜噜噜噜狠狠狠7777视频 | 99久久精品免费看国产四区 | 91综合网|