|
@@ -11,9 +11,14 @@
|
|
|
#import "Push.pbrpc.h"
|
|
|
#import "Push.pbobjc.h"
|
|
|
#import "JYTabBarController.h"
|
|
|
+#import <UIKit/UIKit.h>
|
|
|
|
|
|
+@interface JYgRPCClient() {
|
|
|
+
|
|
|
+ BOOL regStatus;
|
|
|
+}
|
|
|
|
|
|
-@interface JYgRPCClient()
|
|
|
+@property (nonatomic,weak)NSTimer *timer;
|
|
|
|
|
|
|
|
|
@end
|
|
@@ -44,32 +49,49 @@
|
|
|
|
|
|
-(void)initData {
|
|
|
|
|
|
+ //不断监听 5秒执行一次 注册
|
|
|
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)timeFireMethod {
|
|
|
+ if (!regStatus) {
|
|
|
+ [self registeredHost];
|
|
|
+ }else {
|
|
|
+ [self.timer invalidate];
|
|
|
+ self.timer = nil;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+-(void)registeredHost {
|
|
|
+
|
|
|
[GRPCCall useInsecureConnectionsForHost:@"192.168.3.207:5565"];
|
|
|
|
|
|
self.service = [PushService serviceWithHost:@"192.168.3.207:5565"];
|
|
|
RegReq *req = [[RegReq alloc]init];
|
|
|
req.key = @"jy";
|
|
|
req.uuid = @"111122223333";
|
|
|
+
|
|
|
[self.service registerWithRequest:req handler:^(RegResp * _Nullable response, NSError * _Nullable error) {
|
|
|
- NSLog(@"注册接收:%@",response.pushId);
|
|
|
- [[NSUserDefaults standardUserDefaults] setValue:response.pushId forKey:GRPCPushID];
|
|
|
- [GlobalData shareInstance].rpcPushID =response.pushId;
|
|
|
+ if(error==nil){
|
|
|
+ NSLog(@"注册接收成功:%@",response.pushId);
|
|
|
+ regStatus = YES;
|
|
|
+ [[NSUserDefaults standardUserDefaults] setValue:response.pushId forKey:GRPCPushID];
|
|
|
+ [GlobalData shareInstance].rpcPushID =response.pushId;
|
|
|
+ [self listeningRPC];
|
|
|
+ }
|
|
|
}];
|
|
|
-
|
|
|
-
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
- //监听 第一次注册的时候 延时处理
|
|
|
-
|
|
|
+-(void)listeningRPC {
|
|
|
if (![[GlobalData shareInstance].rpcPushID isEqualToString:@""]) {
|
|
|
-// NSLog(@"测试:%@",[GlobalData shareInstance].rpcPushID );
|
|
|
MsgReq *msg = [[MsgReq alloc]init];
|
|
|
msg.pushId = [GlobalData shareInstance].rpcPushID;
|
|
|
[self.service pushMsgWithRequest:msg eventHandler:^(BOOL done, MsgResp * _Nullable response, NSError * _Nullable error) {
|
|
|
if (error==nil) {
|
|
|
[self showLocalPushView:[self dealWithPushData:response]];
|
|
|
}else {
|
|
|
- NSLog(@"通知接收错误:%@",error);
|
|
|
+ NSLog(@"gprc接收接收错误:%@",error);
|
|
|
}
|
|
|
}];
|
|
|
}
|
|
@@ -146,9 +168,7 @@
|
|
|
|
|
|
//推送回调
|
|
|
-(void)grpcCallbackServer:(NSDictionary *)dict {
|
|
|
- NSLog(@"dict:%@",dict);
|
|
|
MsgPushReq *req = [[MsgPushReq alloc]init];
|
|
|
-
|
|
|
req.msgId = dict[@"msgid"];
|
|
|
req.action = [dict[@"type"] intValue];
|
|
|
req.userId = dict[@"userid"];
|