ios極光推送

2021-07-02 17:02:43 字數 3471 閱讀 1022

ios

極光推送整合

分類: ios開發筆記

2014-11-20 13:49

2324人閱讀收藏 

舉報jpush

極光推送

jpushdemo

極光推送整合

jpush整合

稍稍研究了一下極光推送,其實是非常簡單的,不過這個過程也出現了一些問題。

對於應用在前台時,需要額外處理一下。

關於極光推送,由於在ios8之後,有了新的api,因此極光也給我們提供了適配的api。

下面我就把對極光推送相關api的封裝提取出來,希望對大家有幫助,同時也當是總結。

下面是對極光推送而封裝的乙個工具類:

[objc]view plain

copy

print

?////  hybjpushhelper.h

//  jpushdemo

////  created by 黃儀標 on 14/11/20.

//#import 

#import 

/*!* @brief 極光推送相關api封裝

* @author huangyibiao

*/@inte***ce

hybjpushhelper : nsobject  

// 在應用啟動的時候呼叫

+ (void

)setupwithoptions:(

nsdictionary

*)launchoptions;  

+ (void

)registerdevicetoken:(

nsdata

*)devicetoken;  

// ios7以後,才有completion,否則傳nil

+ (void

)handleremotenotification:(

nsdictionary

*)userinfo

completion

:(void

(^)(uibackgroundfetchresult))completion;  

// 顯示本地通知在最前面

+ (void

)showlocalnotificationatfront:(

uilocalnotification

*)notification;  

@end

[objc]view plain

copy

print

?////  hybjpushhelper.m

//  jpushdemo

////  created by 黃儀標 on 14/11/20.

//#import "hybjpushhelper.h"

#import "apservice.h"

@implementation

hybjpushhelper  

+ (void

)setupwithoptions:(

nsdictionary

*)launchoptions  else

#else

// categories 必須為nil

[apserviceregisterforremotenotificationtypes

:(uiremotenotificationtypebadge |  

uiremotenotificationtypesound |  

uiremotenotificationtypealert)  

categories

:nil

];  

#endif

// required

[apservicesetupwithoption

:launchoptions];  

return

;  }  

+ (void

)registerdevicetoken:(

nsdata

*)devicetoken   

+ (void

)handleremotenotification:(

nsdictionary

*)userinfo

completion

:(void

(^)(uibackgroundfetchresult))completion   

return

;  }  

+ (void

)showlocalnotificationatfront:(

uilocalnotification

*)notification   

@end

下面就是測試乙個推送功能了:

[objc]view plain

copy

print

?////  jpushdemo

////  created by 黃儀標 on 14/11/20.

//#import "jpushhelper/hybjpushhelper.h"

@inte***ce

@end

@implementation

- (bool

didfinishlaunchingwithoptions

:(nsdictionary

*)launchoptions   

- (void

didregisterforremotenotificationswithdevicetoken

:(nsdata

*)devicetoken   

- (void

didreceiveremotenotification

:(nsdictionary

*)userinfo   

#if __iphone_os_version_max_allowed >= __iphone_7_0

// ios7.0以後才有此功能

- (void

:(nsdictionary

*)userinfo fetchcompletionhandler  

:(void

(^)(uibackgroundfetchresult))completionhandler   

return

;  }  

#endif

- (void

didreceivelocalnotification

:(uilocalnotification

*)notification   

- (void

didfailtoregisterforremotenotificationswitherror

:(nserror

*)err   

- (void:0

];  

return

;  }  

@end

**:

iOS極光推送

目前的推送 極光,信鴿還是很不錯的選擇,本文主要解釋一下極光推送 這是極光官網的註冊,這裡需要上傳證書 按照官方文件的介紹證書的問題不是很大,boundle id 是根據證書自動識別的 需要說明一下開發環境就是需要上傳測試推送證書,生產環境是上傳測試證書 然後配置環境 設定 search paths...

iOS極光推送整合

稍稍研究了一下極光推送,其實是非常簡單的,不過這個過程也出現了一些問題。對於應用在前台時,需要額外處理一下。關於極光推送,由於在ios8之後,有了新的api,因此極光也給我們提供了適配的api。下面我就把對極光推送相關api的封裝提取出來,希望對大家有幫助,同時也當是總結。下面是對極光推送而封裝的乙...

iOS極光推送整合

稍稍研究了一下極光推送,其實是非常簡單的,不過這個過程也出現了一些問題。對於應用在前台時,需要額外處理一下。關於極光推送,由於在ios8之後,有了新的api,因此極光也給我們提供了適配的api。下面我就把對極光推送相關api的封裝提取出來,希望對大家有幫助,同時也當是總結。下面是對極光推送而封裝的乙...