第三方-激光推送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:;
    }

}
时间: 2024-08-29 05:26:28

第三方-激光推送2.1.0的相关文章

友盟第三方消息推送使用

1.首先你得有一个友盟的账号友盟官网 2.注册了账号之后要注册应用 这里要注意的信息 3.下载友盟消息推送sdk友盟推送sdk下载地址 4.准备工作都做好之后可以进行环境配置了 打开File→Project Structure 确认之后,就将PushSDK依赖到你的项目中了 它里面的东西你都可以调用了,它里面配置好了各种权限等等 可以省去很多步骤 官方提示需要注意的东西: 在自己项目的build.gradle里面一定要配置applicationId,PushSDK下的AndroidManifes

Android第三方消息推送

====================问题描述==================== 我看现在第三方的消息推送怎么都是从网页推到手机上的?有没有从手机到手机的,即时聊天那样的?有哪些? ====================解决方案1==================== 终端直接一般依靠服务器实现,如果终端不经过服务器中转,那就不能实现广域网通讯.终端之间可以通过udp广播实现局域网内消息推送. ====================解决方案2====================

如何实现从Android第三方平台推送微信公众号

最近心血来潮,想要尝试写写有关实现Android平台第三方应用软件去跳转到微信平台的代码.我只是先暂时写写我的思路,如后期实现,便将主要代码附上. 微信公众平台官方宣布微信沟通接口正式上线,用户可以在移动应用中,点击跳转到微信客户端内,用户已关注公众号时会进入会话界面,未关注则进入资料页. 2014年11月6日,微信开放平台(open.weixin.qq.com)发公告表示,将把沟通接口开放给开发者,以下是公告原文:(文章来自于http://www.vkda.cn/news/index/deta

集成激光推送

1.进入https://www.jpush.cn/common/products,注册用户,下载ADK,查看使用说明 2.简单的在AppDelegate中添加如下代码 #import "AppDelegate.h" #import "APService.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)applicati

解决激光推送手机运行时内存杀死进程依然能收到推送

} if (ACTION_BOOT.equals(intent.getAction())||ACTION_NET_CHANGE.equals(intent.getAction())){ Intent service = new Intent(context,DownloadService.class); context.startService(service); Intent pSrvice = new Intent(context,PushService.class); context.st

最新iOS开发者账号相关:二、第三方推送添加(2015.10.9)

现在的一些第三方的推送平台挺好用,主要是因为他们有类似微信公众平台一样的管理后台,简单易用,封装了很多开发者需要的推送功能. 这种三方的框架集成比较简单,可以参考个推的APPDemo进行集成,主要就是导入库,然后在APPdelegate配置下就好了. demo以及文档地址:http://docs.igetui.com/pages/viewpage.action?pageId=1934080 代码的地方需要注意的是: 在线的推送和离线的推送入口是不一样的 离线的时候,是通过苹果服务器周转的推送的d

Android使用第三方推送(二)百度云推送

时间过得好快,转眼就是12月了.工作了之后,发现节奏停不下来,像是被上了发条,再也由不得自己.工作日如流水,周末更是转瞬即逝.其实想想也是有时间的,只不过没有很好的利用,或者花在了没有意义的事情上面.人总是有惰性的,但是持续下去就不好了. 上周开始接触第三方云推送,先后体验了极光推送,个推和百度云推送,也感受了各个平台的特性.有的部署便捷,有的功能强大,有的稳定可靠.今天简单介绍一下百度云推送的使用. 百度云推送给我的感觉就是稳定可靠,毕竟是百度出品,值得信赖.而且富媒体推送也是免费,又胜出极光

Android消息推送:手把手教你集成小米推送

前言 在Android开发中,消息推送功能的使用非常常见. 为了降低开发成本,使用第三方推送是现今较为流行的解决方案. 今天,我将手把手教大家如何在你的应用里集成小米推送 该文档基于小米推送官方Demo,并给出简易推送Demo 看该文档前,请先阅读我写的另外两篇文章: 史上最全解析Android消息推送解决方案 Android推送:第三方消息推送平台详细解析 目录 1. 官方Demo解析 首先,我们先对小米官方的推送Demo进行解析. 请先到官网下载官方Demo和SDK说明文档 1.1 Demo

极光推送开发(一)

网上面关于极光推送的文章不多,再此写一篇文章进行说明. 极光推送的官方网站:https://www.jpush.cn/common/ (一)准备工作 在官方网站中,它已经对极光推送如何开发进行了详细的说明,照着上面的步骤是不难把极光推送应用到自己开发的客户端中的. 极光推送官方网站的说明文档链接: http://docs.jpush.io/guideline/android_guide/ 点击打开如图所示: 在这里详细介绍了集成的步骤. 首先到资源下载处下载客户端SDK,本文主要讲解androi