|
@@ -11,14 +11,14 @@
|
|
#import "Push.pbrpc.h"
|
|
#import "Push.pbrpc.h"
|
|
#import "Push.pbobjc.h"
|
|
#import "Push.pbobjc.h"
|
|
#import "JYTabBarController.h"
|
|
#import "JYTabBarController.h"
|
|
-#import <UIKit/UIKit.h>
|
|
|
|
|
|
+
|
|
|
|
|
|
@interface JYgRPCClient() {
|
|
@interface JYgRPCClient() {
|
|
|
|
|
|
BOOL regStatus;
|
|
BOOL regStatus;
|
|
}
|
|
}
|
|
|
|
|
|
-@property (nonatomic,weak)NSTimer *timer;
|
|
|
|
|
|
+@property (nonatomic,weak)NSTimer *hostTimer;
|
|
|
|
|
|
|
|
|
|
@end
|
|
@end
|
|
@@ -36,6 +36,10 @@
|
|
return manager;
|
|
return manager;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+-(NSString *)getUID{
|
|
|
|
+ return [UIDevice currentDevice].identifierForVendor.UUIDString;;
|
|
|
|
+}
|
|
|
|
+
|
|
- (instancetype)init
|
|
- (instancetype)init
|
|
{
|
|
{
|
|
if (self = [super init])
|
|
if (self = [super init])
|
|
@@ -49,28 +53,42 @@
|
|
|
|
|
|
-(void)initData {
|
|
-(void)initData {
|
|
|
|
|
|
- //不断监听 5秒执行一次 注册
|
|
|
|
- self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
|
|
|
|
|
|
+ //不断监听 10秒执行一次 注册
|
|
|
|
+ self.hostTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(hostTimerFireMethod) userInfo:nil repeats:YES];
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
--(void)timeFireMethod {
|
|
|
|
|
|
+-(void)hostTimerFireMethod {
|
|
|
|
+ NSLog(@"执行一次请求获取host");
|
|
if (!regStatus) {
|
|
if (!regStatus) {
|
|
- [self registeredHost];
|
|
|
|
|
|
+ [self getHost];
|
|
}else {
|
|
}else {
|
|
- [self.timer invalidate];
|
|
|
|
- self.timer = nil;
|
|
|
|
|
|
+ [self.hostTimer invalidate];
|
|
|
|
+ self.hostTimer = nil;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
--(void)registeredHost {
|
|
|
|
-
|
|
|
|
- [GRPCCall useInsecureConnectionsForHost:@"192.168.3.207:5565"];
|
|
|
|
-
|
|
|
|
- self.service = [PushService serviceWithHost:@"192.168.3.207:5565"];
|
|
|
|
|
|
+-(void)getHost {
|
|
|
|
+ //请求
|
|
|
|
+ [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/config",kHost] parameters:nil progress:^(NSProgress *progress) {
|
|
|
|
+ } success:^(id responseObject) {
|
|
|
|
+ if ([responseObject valueForKey:@"pushGrpcServer"]) {
|
|
|
|
+ NSString *pushGrpcServer = [NSString stringWithFormat:@"%@",responseObject[@"pushGrpcServer"]];
|
|
|
|
+ [self registeredHost:pushGrpcServer];
|
|
|
|
+ }
|
|
|
|
+ } failure:^(NSError *error) {
|
|
|
|
+ NSLog(@"error=%@",error);
|
|
|
|
+ }];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+-(void)registeredHost:(NSString *)host {
|
|
|
|
+ [GRPCCall useInsecureConnectionsForHost:host];
|
|
|
|
+ self.service = [PushService serviceWithHost:host];
|
|
|
|
+ NSString *uidStr = [self getUID];
|
|
RegReq *req = [[RegReq alloc]init];
|
|
RegReq *req = [[RegReq alloc]init];
|
|
req.key = @"jy";
|
|
req.key = @"jy";
|
|
- req.uuid = @"111122223333";
|
|
|
|
|
|
+ req.uuid = uidStr;
|
|
|
|
|
|
[self.service registerWithRequest:req handler:^(RegResp * _Nullable response, NSError * _Nullable error) {
|
|
[self.service registerWithRequest:req handler:^(RegResp * _Nullable response, NSError * _Nullable error) {
|
|
if(error==nil){
|
|
if(error==nil){
|