第三方-雷射推送2.1.0,第三方雷射推2.1.0

來源:互聯網
上載者:User

第三方-雷射推送2.1.0,第三方雷射推2.1.0

1.首先建立一個類目

#import "AppDelegate+JPush.h"#import "JPUSHService.h"#import "WJNotifier.h"//依賴檔案static NSString *JIGUANG_PUSH_KEY = @"4cdcd543c073753fb8932246";//key//NSString *_tag = nil;@implementation AppDelegate (JPush)- (void)initJpush:(NSDictionary *)launchOptions{    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {        //可以添加自訂categories        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |                                                          UIUserNotificationTypeSound |                                                          UIUserNotificationTypeAlert)                                              categories:nil];    } else {        //categories 必須為nil        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |                                                          UIRemoteNotificationTypeSound |                                                          UIRemoteNotificationTypeAlert)                                              categories:nil];    }    // Required    //如需相容舊版本的方式,請依舊使用[JPUSHService setupWithOption:launchOptions]方式初始化和同時使用pushConfig.plist檔案聲明appKey等配置內容。    [JPUSHService setupWithOption:launchOptions appKey:JIGUANG_PUSH_KEY channel:@"0" apsForProduction:YES];}- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {        // Required    [JPUSHService registerDeviceToken:deviceToken];}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {        // Required,For systems with less than or equal to iOS6    [JPUSHService handleRemoteNotification:userInfo];}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {        // IOS 7 Support Required    [JPUSHService handleRemoteNotification:userInfo];    completionHandler(UIBackgroundFetchResultNewData);    if (application.applicationState == UIApplicationStateActive) {        //音效播放在裡面        [WJNotifier showNotifer:userInfo[@"aps"][@"alert"]];    }    [CoreManager setJPushNumber];    [[NSNotificationCenter defaultCenter]postNotificationName:notice_jpush object:@"1"];}- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {        //Optional    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);}@end

 

2.在下面方法裡面調用初始化

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 

3.在根控制器中監聽狀態

- (void)dealloc {    [self unObserveAllNotifications];}- (void)viewDidLoad {    [super viewDidLoad];    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];    [defaultCenter addObserver:self                      selector:@selector(networkDidSetup:)                          name:kJPFNetworkDidSetupNotification                        object:nil];    [defaultCenter addObserver:self                      selector:@selector(networkDidClose:)                          name:kJPFNetworkDidCloseNotification                        object:nil];    [defaultCenter addObserver:self                      selector:@selector(networkDidRegister:)                          name:kJPFNetworkDidRegisterNotification                        object:nil];    [defaultCenter addObserver:self                      selector:@selector(networkDidLogin:)                          name:kJPFNetworkDidLoginNotification                        object:nil];    [defaultCenter addObserver:self                      selector:@selector(networkDidReceiveMessage:)                          name:kJPFNetworkDidReceiveMessageNotification                        object:nil];    [defaultCenter addObserver:self                      selector:@selector(serviceError:)                          name:kJPFServiceErrorNotification                        object:nil];    }- (void)unObserveAllNotifications {    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];    [defaultCenter removeObserver:self                             name:kJPFNetworkDidSetupNotification                           object:nil];    [defaultCenter removeObserver:self                             name:kJPFNetworkDidCloseNotification                           object:nil];    [defaultCenter removeObserver:self                             name:kJPFNetworkDidRegisterNotification                           object:nil];    [defaultCenter removeObserver:self                             name:kJPFNetworkDidLoginNotification                           object:nil];    [defaultCenter removeObserver:self                             name:kJPFNetworkDidReceiveMessageNotification                           object:nil];    [defaultCenter removeObserver:self                             name:kJPFServiceErrorNotification                           object:nil];}- (void)networkDidSetup:(NSNotification *)notification {    NSLog(@"已串連");}- (void)networkDidClose:(NSNotification *)notification {}- (void)networkDidRegister:(NSNotification *)notification {    NSLog(@"%@", [notification userInfo]);    NSLog(@"登入");}- (void)networkDidLogin:(NSNotification *)notification {    NSLog(@"已登入");    if ([JPUSHService registrationID]) {        NSLog(@"get RegistrationID");
    //轉入別名 [self resetAliasAndTagWithTag:[UserManager sharedUserInfoWithPlist].name]; }}- (void)networkDidReceiveMessage:(NSNotification *)notification {}- (void)serviceError:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; NSString *error = [userInfo valueForKey:@"error"]; NSLog(@"%@", error);}- (void)resetAliasAndTagWithTag:(NSString *)tag{ __autoreleasing NSMutableSet * tags = [NSMutableSet set]; if (tag == nil) { [tags addObject:@""]; }else { [tags addObject:tag]; } //沒有直接傳入@"" [JPUSHService setTags:[NSSet set] alias:tag callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];}- (void)tagsAliasCallback:(int)iResCode tags:(NSSet *)tags alias:(NSString *)alias{ NSLog(@"%d",iResCode); NSLog(@"標籤設定成功,標籤名為%@",alias); switch (iResCode) { case 6002: [self resetAliasAndTagWithTag:[UserManager sharedUserInfoWithPlist].name]; break; default:; } }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.