添加回调数据的解析过程

This commit is contained in:
xuemh
2018-08-06 22:51:30 +08:00
parent 1028ffa9ac
commit 5614a0a931
5 changed files with 61 additions and 4 deletions
@@ -128,6 +128,10 @@
#pragma mark - IFishHotpotUDPHelperDelegate
- (void)udpHelperCommandExecutedSuccess {
[self.view makeToast:@"连接设置成功"];
}
- (void)udpHelperMessage:(NSString *)msg {
[self.view makeToast:msg];
}
@@ -12,6 +12,7 @@
#import "ConnectHotspotModel.h"
#import "ResetDeviceModel.h"
#import "RestartDeviceModel.h"
#import "IFishUDPHelperBackMsgModel.h"
@interface IFishHotpotUDPHelper ()
{
@@ -135,10 +136,14 @@
NSLog(@"didReceiveData%@",result);
NSLog(@"port%hu",port);
AppDelegate *app =(AppDelegate*)[UIApplication sharedApplication].delegate;
[app.window makeToast:[NSString stringWithFormat:@"收到答复:%@", result]];
if ([self.delegate respondsToSelector:@selector(udpHelperCommandExecutedSuccess)]) {
[self.delegate udpHelperCommandExecutedSuccess];
IFishUDPHelperBackMsgModel *model = [[IFishUDPHelperBackMsgModel alloc] initWithData:data];
if ([model.result isEqualToString:@"01"]) {
if ([self.delegate respondsToSelector:@selector(udpHelperCommandExecutedSuccess)]) {
[self.delegate udpHelperCommandExecutedSuccess];
}
} else {
AppDelegate *app =(AppDelegate*)[UIApplication sharedApplication].delegate;
[app.window makeToast:[NSString stringWithFormat:@"收到答复:%@", result]];
}
[self.loopTimer invalidate];
return YES;
@@ -0,0 +1,19 @@
//
// IFishUDPHelperBackMsgModel.h
// Ifish
//
// Created by Minghao Xue on 2018/8/6.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface IFishUDPHelperBackMsgModel : NSObject
@property (nonatomic, copy) NSString *result;
@property (nonatomic, copy) NSString *changshang;
@property (nonatomic, copy) NSString *device;
- (instancetype)initWithData:(NSData *)data;
@end
@@ -0,0 +1,23 @@
//
// IFishUDPHelperBackMsgModel.m
// Ifish
//
// Created by Minghao Xue on 2018/8/6.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import "IFishUDPHelperBackMsgModel.h"
@implementation IFishUDPHelperBackMsgModel
- (instancetype)initWithData:(NSData *)data {
if (self = [super init]) {
NSString*totalString=[dataContorl dataToHexString:data];
self.result = [totalString substringWithRange:NSMakeRange(30, 2)];
self.changshang = [totalString substringWithRange:NSMakeRange(32, 2)];
self.device = [totalString substringWithRange:NSMakeRange(34, 2)];
}
return self;
}
@end