自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)基礎(chǔ)學(xué)習(xí) 在程序里設(shè)置Push

移動(dòng)開發(fā) iOS
本文介紹的是iPhone開發(fā)基礎(chǔ)學(xué)習(xí) 在程序里設(shè)置Push ,很詳細(xì)的為大家講解,我們先來看恩日。

iPhone開發(fā)基礎(chǔ)學(xué)習(xí) 在程序里設(shè)置Push是本文要介紹的內(nèi)容,最近做項(xiàng)目有一個(gè)需求,要在程序得系統(tǒng)設(shè)置里進(jìn)行push的設(shè)置。在網(wǎng)上搜了幾天資料沒找著啥。今天忽然心血來潮跟蹤系統(tǒng)注冊(cè)push時(shí)得代碼,居然發(fā)現(xiàn)有可行得解決方法,思路如下:

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

  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推送類型。然后再調(diào)用registerForRemoteNotificationTypes進(jìn)行修改。若要關(guān)閉程序得push服務(wù),可調(diào)用unregisterForRemoteNotifications.

3、補(bǔ)充:以上想法以實(shí)現(xiàn)。補(bǔ)充部分代碼。settingsData為tableview的數(shù)據(jù)源數(shù)組

a、獲取系push設(shè)置,用于顯示給用戶

  1. //push設(shè)置  
  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.                                      @"標(biāo)記", @"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.                               @"通知設(shè)置", @"groupName",  
  43.                               pushOptions,    @"data",  
  44.                               nil];  
  45. [self.settingsData addObject:pushConfig];  
  46. [pushOptions release];  
  47. [pushConfig release]; 

b、獲取用戶設(shè)置的數(shù)據(jù)放入pushdata,然后向系統(tǒng)提交設(shè)置

  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];  

希望以上思路對(duì)有這方面需求得人有幫助。以上方案我暫未用于代碼實(shí)現(xiàn)。若有問題。請(qǐng)留言共同商討。

小結(jié):iPhone開發(fā)基礎(chǔ)學(xué)習(xí) 在程序里設(shè)置Push的內(nèi)容介紹完了,希望本文對(duì)你有所幫助1更多相關(guān)內(nèi)容請(qǐng)參考編輯推薦。

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-18 14:33:32

2011-07-07 17:04:33

iPhone Action Objective-

2011-07-18 14:59:20

iPhone Objective-

2011-07-25 16:47:01

HTTP Server PUSH

2012-04-26 13:30:05

iPhoneApp Store發(fā)布程序

2011-08-10 16:44:56

iPhone代理設(shè)計(jì)模式

2011-07-25 18:07:29

iPhone Push Notificati

2011-08-15 10:06:22

iPhone開發(fā)nib 文件

2011-08-08 10:10:14

iPhone開發(fā) 圖片 方法

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-01 18:27:58

iPhone開發(fā) UISearchBa

2011-07-18 09:35:29

iPhone 框架

2011-03-08 16:57:13

proftpd

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-08-05 14:48:06

iPhone應(yīng)用 異步隊(duì)列

2011-08-18 10:39:46

iPhone開發(fā)界面

2011-07-20 17:10:05

iPhone iAd

2011-07-26 14:18:20

2011-08-08 15:56:18

iPhone 震動(dòng) NSUserDefa

2011-07-27 16:46:04

iPhone iPhone破解 MacPort
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)