关于javapushy的信息

博主:adminadmin 2022-11-29 04:34:07 60

本篇文章给大家谈谈javapushy,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

iOS - 前后台 推送笔记

    1、注册推送通知

    目前支持iOS 10.0 以上版本:

   导入框架#import UserNotifications/UserNotifications.h 并实现代理

         if ( @available (iOS10.0, *)) {

        [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionAlert) completionHandler:^( BOOL granted, NSError * _Nullable error) {

            NSLog(@"%@",error);

            if (!error) {

                NSLog(@"授权成功");

            }

        }];

        UNNotificationCategory* generalCategory = [UNNotificationCategory

                                                           categoryWithIdentifier:@"GENERAL"

                                                           actions:@[]

                                                           intentIdentifiers:@[]

                                                           options:UNNotificationCategoryOptionCustomDismissAction];

                // Create the custom actions for expired timer notifications.

                UNNotificationAction* snoozeAction = [UNNotificationAction

                                                      actionWithIdentifier:@"SNOOZE_ACTION"

                                                      title:@"Snooze"

                                                      options:UNNotificationActionOptionAuthenticationRequired];

                UNNotificationAction* stopAction = [UNNotificationAction

                                                    actionWithIdentifier:@"STOP_ACTION"

                                                    title:@"Stop"

                                                    options:UNNotificationActionOptionDestructive];

                UNNotificationAction* forAction = [UNNotificationAction

                                                    actionWithIdentifier:@"FOR_ACTION"

                                                    title:@"forAction"

                                                    options:UNNotificationActionOptionForeground];

                // Create the category with the custom actions.

                UNNotificationCategory* expiredCategory = [UNNotificationCategory

                                                           categoryWithIdentifier:@"TIMER_EXPIRED"

                                                           actions:@[snoozeAction, stopAction,forAction]

                                                           intentIdentifiers:@[]

                                                           options:UNNotificationCategoryOptionNone];

                // Register the notification categories.

                UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];

                [centersetDelegate: self ];

                [centersetNotificationCategories:[NSSetsetWithObjects:generalCategory, expiredCategory,

                                                   nil ]];

                [[UIApplication sharedApplication] registerForRemoteNotifications];

    } else {

    }

    2、获取deviceToken

- ( void )application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    //保存deviceToken

    NSLog(@"register success: %@",deviceToken);

}

    3、生成测试环境、生产环境证书:

    4、注册deviceToken到后台服务

        [XXXNetManager  registDeviceToken:deviceToken];

    5、接收推送通知(APP在显示状态下接收,APP在后台或进程关闭下接收)

    //将要推送

- ( void )userNotificationCenter:(UNUserNotificationCenter*)centerwillPresentNotification:(UNNotification*)notificationwithCompletionHandler:( void (^)(UNNotificationPresentationOptionsoptions))completionHandler__API_AVAILABLE(macos(10.14), ios(10.0), watchos(3.0), tvos(10.0))

{

    NSLog(@"%s", __func__ );

    NSLog(@"%@",notification.request.content.userInfo);

}

//完成推送

- ( void )userNotificationCenter:(UNUserNotificationCenter*)centerdidReceiveNotificationResponse:(UNNotificationResponse*)responsewithCompletionHandler:( void (^)( void ))completionHandler__API_AVAILABLE(macos(10.14), ios(10.0), watchos(3.0))__API_UNAVAILABLE(tvos)

{

    NSLog(@"%s", __func__ );

    NSLog(@"%@",response.notification.request.content.userInfo);

}

    6、读取aps:下的消息体,解析处理对应业务逻辑。

    UNNotificationRequest-UNNotificationContent-(NSDictionary *)userInfo

    使用SmartPush推送测试工具 测试:

    本地推送案例比较多,这里不再记录。

   1、 使用MQTT 发布、订阅方式 ,  根据与后台协商好的用户名、密码、心跳时间、QoS级别等发起连接。

2、连接状态检测:

-( void )handleEvent:(MQTTSession*)sessionevent:(MQTTSessionEvent)eventCodeerror:(NSError*)error{

     if (eventCode == MQTTSessionEventConnected) {

        NSLog(@"2222222 连接MQTT 成功");

    } else if (eventCode == MQTTSessionEventConnectionRefused){

        NSLog(@"MQTT 拒绝连接");

    } else if (eventCode ==MQTTSessionEventConnectionClosed){

        NSLog(@"MQTT 连接关闭");

    } else if (eventCode ==  MQTTSessionEventConnectionError){

        NSLog(@"MQTT 连接错误");

    } else if (eventCode == MQTTSessionEventProtocolError){

        NSLog(@"MQTT 协议错误");

    } else {

        NSLog(@"MQTT 其他错误");

    }

     if (error) {

        NSLog(@"连接报错 -- %@",error);

    }

}

在连接成功后,发起订阅:

一次性订阅多个主题  @"%@/test/#"

MQTT主题(Topic)支持’+’, ‘#’的通配符,’+’通配一个层级,’#’通配多个层级(必须在末尾)

解释一下,#表示,test下面的所有主题,假如你有5个主题,你这样就可以一次性订阅完成,然后你在返回的数据中,判断对应的主题处理数据就可以了.

使用MQTTSessionManager 初始化 并实现代理,具体细节如下:

self .manager = [[MQTTSessionManager alloc]init];

    self .manager.delegate = self ;

    self .manager.subscriptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:MQTTQosLevelExactlyOnce] forKey:[NSString stringWithFormat:@"%@/#", self .base]];

    [ self .manager connectTo:kMQTTHost //服务器地址

                       port:kMQTTPort//服务端端口号

                        tls: false   //是否使用tls协议,mosca是支持tls的,如果使用了要设置成true

                  keepalive:60  //心跳时间,单位秒,每隔固定的时间发送心跳包

                      clean: false   //session是否清除,这个需要注意,如果是false,代表保持登录,如果客户端离线了再次登录就可以接收到离线消息。注意:QoS为1和QoS为2,并需订阅和发送一致

                       auth: true //是否使用登录验证,和下面的user和pass参数组合使用

                       user: self .uid  //用户名

                       pass: self .password  //密码

                       will: false   //异常离线消息体。自定义的异常离线消息,约定好格式就可以了

                  willTopic:@""  //如果客户端异常离线发送的消息,当前参数是哪个topic用来传输异常离线消息,这里的异常离线消息都指的是客户端掉线后发送的掉线消息

                    willMsg: nil   //具体内容

                    willQos:0  //接收离线消息的级别 0、1、2

             willRetainFlag: false   //只有在为true时, Will Qos和 Will retain 才会被读取,此时消息体payload中要出现Will Topic 和Will Message具体内容,否则,Will QoS和 Will Retain 值会被忽略掉

               withClientId: nil   //客户端id,需要特别指出的是这个id需要全局唯一,因为服务器是根据这个来区分不同的客户端的,默认情况下一个id登录后,假如有另外的连接以这个id登录,上一个连接会被踢下线。

             securityPolicy: nil   //消息通信的安全策略设置

               certificates: nil   //证书数组

              protocolLevel:MQTTProtocolVersion311  //协议等级设置

             connectHandler:^(NSError*error) {

         if (error) {

            NSLog(@"error === %@",error);

        }

    }];

}

Pushy是用于发送APN(iOS,MacOS和Safari)推送通知的Java库。它由Turo的工程师编写和维护。

Pushy使用Apple的基于HTTP / 2的APN协议发送推送通知,并支持TLS和基于令牌的身份验证。

原文链接:

    基于 nutzboot + netty + redis + kafka 实现的MQTT服务broker

    详细细节说明请看链接:

关于javapushy和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。