Commit be11be68 by 刘卓鑫

ad广告修改

parent 64eb0052
...@@ -27,6 +27,15 @@ ...@@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9142D2B61F35C84E004F90CF"
BuildableName = "ColorfulSchool.app"
BlueprintName = "ColorfulSchool"
ReferencedContainer = "container:ColorfulSchool.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
...@@ -49,17 +58,6 @@ ...@@ -49,17 +58,6 @@
</BuildableReference> </BuildableReference>
</TestableReference> </TestableReference>
</Testables> </Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9142D2B61F35C84E004F90CF"
BuildableName = "ColorfulSchool.app"
BlueprintName = "ColorfulSchool"
ReferencedContainer = "container:ColorfulSchool.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
...@@ -81,11 +79,9 @@ ...@@ -81,11 +79,9 @@
ReferencedContainer = "container:ColorfulSchool.xcodeproj"> ReferencedContainer = "container:ColorfulSchool.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release" buildConfiguration = "Debug"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
...@@ -105,7 +101,7 @@ ...@@ -105,7 +101,7 @@
buildConfiguration = "Debug"> buildConfiguration = "Debug">
</AnalyzeAction> </AnalyzeAction>
<ArchiveAction <ArchiveAction
buildConfiguration = "Release" buildConfiguration = "Debug"
revealArchiveInOrganizer = "YES"> revealArchiveInOrganizer = "YES">
</ArchiveAction> </ArchiveAction>
</Scheme> </Scheme>
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
_isPlaying = NO; _isPlaying = NO;
//启动环境 //启动环境
[APIManager sharedAPIManager].lauchEnvironment = ZXColorfulSchoolEnvironmentProduct; [APIManager sharedAPIManager].lauchEnvironment = ZXColorfulSchoolEnvironmentTest;
//极光推送 //极光推送
[self initPushWithOptions:launchOptions isProduct:YES]; [self initPushWithOptions:launchOptions isProduct:YES];
......
// //
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
- (void) startLauchAd { - (void) startLauchAd {
NSString *url = [[NSString stringWithFormat:@"http://open.adview.cn/agent/openRequest.do?ver=2.7.0&n=1&appid=SDK20191516030954opvyhmi3khwalbw&pt=4&posId=POSIDn5ahrkelm20e&pack=com.pxkjformal.parallelcampus&w=640&h=960&tab=0&ip=%@&os=1&bdr=%@&tp=%@&brd=Apple&ua=%@&sw=%f&sh=%f&deny=%f&sn=%@&mac=%@&didsha1=%@&dpidsha1=%@&macsha1=%@&didmd5=%@&dpidmd5=%@&macmd5=%@&nt=%@&nop=%@&country=ISO-3166-1 Alpha-3&language=alpha-2/ISO 639- 1&tm=0&time=%@&token=%@&html5=2", [BYHelp getIPAddress], [[UIDevice currentDevice] systemVersion], [ZXTool getCurrentDevice], [ZXTool returnUserAgent], kScreenWidth, kScreenHeight, [UIScreen mainScreen].scale, [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString], [self macAddress], [self iemi],[self sha1:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], [self sha1:[self macAddress]], [ZXTool md5:[self iemi]], [ZXTool md5:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], [ZXTool md5:[self macAddress]], [ZXTool returnNetworkStatus]==1?@"WIFI":@"4G", [ZXTool currentYYS], [ZXTool getCurrentTimeStamp], [ZXTool md5:[NSString stringWithFormat:@"SDK20191516030954opvyhmi3khwalbw%@", [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]]]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *url = [[NSString stringWithFormat:@"http://open.adview.cn/agent/openRequest.do?ver=2.7.0&n=1&appid=SDK20191516030954opvyhmi3khwalbw&pt=4&posId=POSIDn5ahrkelm20e&pack=com.pxkjformal.parallelcampus&w=%f&h=%f&tab=0&ip=%@&os=1&bdr=%@&tp=%@&brd=Apple&ua=%@&sw=%f&sh=%f&deny=%f&sn=%@&mac=%@&didsha1=%@&dpidsha1=%@&macsha1=%@&didmd5=%@&dpidmd5=%@&macmd5=%@&nt=%@&nop=%@&country=ISO-3166-1 Alpha-3&language=alpha-2/ISO 639- 1&tm=0&time=%@&token=%@", kScreenWidth, kScreenHeight, [BYHelp getIPAddress], [[UIDevice currentDevice] systemVersion], [ZXTool getCurrentDevice], [ZXTool returnUserAgent], kScreenWidth, kScreenHeight, [UIScreen mainScreen].scale, [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString], [self macAddress], [self iemi],[self sha1:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], [self sha1:[self macAddress]], [ZXTool md5:[self iemi]], [ZXTool md5:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], [ZXTool md5:[self macAddress]], [ZXTool returnNetworkStatus]==1?@"WIFI":@"4G", [ZXTool currentYYS], [ZXTool getCurrentTimeStamp], [ZXTool md5:[NSString stringWithFormat:@"SDK20191516030954opvyhmi3khwalbw%@", [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]]]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// NSDictionary *dic = @{@"ver":@"4.0.1",@"n":@"1", @"appid":@"SDK20191516030954opvyhmi3khwalbw",@"pt":@"4", @"posId":@"POSIDn5ahrkelm20e", @"pack":@"com.pxkjformal.parallelcampus", @"w":@(kScreenWidth), @"h":@(kScreenHeight), @"tab":@"0", @"ip":[BYHelp getIPAddress], @"bdr":[[UIDevice currentDevice] systemVersion], @"tp":@"", @"brd":@"Apple", @"ua":[ZXTool getCurrentDevice], @"sw":@(kScreenWidth), @"sh":@(kScreenHeight), @"deny":@([UIScreen mainScreen].scale), @"sn":@"867FD2E0-F1FB-4D05-B3AE-383951FEE6EA", @"mac":[self macAddress], @"didsha1":[self iemi], @"dpidsha1":[self sha1:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], @"macsha1":[self sha1:[self macAddress]], @"didmd5":[ZXTool md5:[self iemi]], @"dpidmd5":[ZXTool md5:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], @"macmd5":[ZXTool md5:[self macAddress]], @"nt":([ZXTool returnNetworkStatus]==1?@"WIFI":@"4G"), @"nop":[ZXTool currentYYS], @"country":@"ISO-3166-1 Alpha-3", @"language":@"alpha-2/ISO639- 1", @"tm":@"0", @"time":[ZXTool getCurrentTimeStamp], @"token":[ZXTool md5:[NSString stringWithFormat:@"SDK20191516030954opvyhmi3khwalbw%@", [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]]]}; // NSDictionary *dic = @{@"ver":@"4.0.1",@"n":@"1", @"appid":@"SDK20191516030954opvyhmi3khwalbw",@"pt":@"4", @"posId":@"POSIDn5ahrkelm20e", @"pack":@"com.pxkjformal.parallelcampus", @"w":@(kScreenWidth), @"h":@(kScreenHeight), @"tab":@"0", @"ip":[BYHelp getIPAddress], @"bdr":[[UIDevice currentDevice] systemVersion], @"tp":@"", @"brd":@"Apple", @"ua":[ZXTool getCurrentDevice], @"sw":@(kScreenWidth), @"sh":@(kScreenHeight), @"deny":@([UIScreen mainScreen].scale), @"sn":@"867FD2E0-F1FB-4D05-B3AE-383951FEE6EA", @"mac":[self macAddress], @"didsha1":[self iemi], @"dpidsha1":[self sha1:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], @"macsha1":[self sha1:[self macAddress]], @"didmd5":[ZXTool md5:[self iemi]], @"dpidmd5":[ZXTool md5:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]], @"macmd5":[ZXTool md5:[self macAddress]], @"nt":([ZXTool returnNetworkStatus]==1?@"WIFI":@"4G"), @"nop":[ZXTool currentYYS], @"country":@"ISO-3166-1 Alpha-3", @"language":@"alpha-2/ISO639- 1", @"tm":@"0", @"time":[ZXTool getCurrentTimeStamp], @"token":[ZXTool md5:[NSString stringWithFormat:@"SDK20191516030954opvyhmi3khwalbw%@", [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]]]};
[[ZXAdViewService sharedManager] POST:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { [[ZXAdViewService sharedManager] POST:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
......
// //
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
} }
for (NSArray *arr in [dic allValues]) { for (NSArray *arr in [dic allValues]) {
for (NSString *url in arr) { for (NSString *url in arr) {
[[self sharedManager] GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { [[self sharedManager] GET:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
NSLog(@"xx"); NSLog(@"xx");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"xx"); NSLog(@"xx");
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
return; return;
} }
for (NSString *url in arr) { for (NSString *url in arr) {
[[self sharedManager] GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {}]; [[self sharedManager] GET:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {}];
} }
} }
+(AFHTTPSessionManager *)sharedManager +(AFHTTPSessionManager *)sharedManager
......
// //
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#import "enlargeClickRegionBtn.h" #import "enlargeClickRegionBtn.h"
#import "CropImageController.h" #import "CropImageController.h"
#import "ZXAdViewService.h"
#import "ZXBannerJumpViewController.h"
@interface ZXHomePageViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, CropImageDelegate> @interface ZXHomePageViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, CropImageDelegate>
/** tableview */ /** tableview */
@property (nonatomic, strong) UITableView *myTableView; @property (nonatomic, strong) UITableView *myTableView;
...@@ -92,14 +95,28 @@ ...@@ -92,14 +95,28 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUserNameAction:) name:@"changeUserNameNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUserNameAction:) name:@"changeUserNameNotification" object:nil];
//测试按钮 //测试按钮
// UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, kScreenHeight - 150, 80, 80)]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, kScreenHeight - 150, 80, 80)];
// [self.view addSubview:btn]; [self.view addSubview:btn];
// btn.backgroundColor = [UIColor orangeColor]; btn.backgroundColor = [UIColor orangeColor];
// [[btn rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(id x) { [[btn rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(id x) {
// UIViewController *vc = [[NSClassFromString(@"DC_ZXWashTabbarViewController") alloc] init]; [[ZXAdViewService sharedManager] GET:@"http://192.168.1.145:8081/alimama/taobao/tbk/dg/optimus/material" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
// vc.hidesBottomBarWhenPushed = YES; NSString *ss = responseObject[@"data"][@"tbk_uatm_favorites_item_get_response"][@"results"][@"uatm_tbk_item"][0][@"item_url"];
NSLog(@"%@", ss);
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"¥20s6YM1uv7v¥";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"taobao://item.taobao.com"]];
// ZXBannerJumpViewController *vc = [[ZXBannerJumpViewController alloc] init];
// vc.jumpUrl = ss;
// [self.navigationController pushViewController:vc animated:YES]; // [self.navigationController pushViewController:vc animated:YES];
// }]; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", error);
}];
}];
} }
- (void)viewWillLayoutSubviews { - (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews]; [super viewWillLayoutSubviews];
...@@ -167,6 +184,7 @@ ...@@ -167,6 +184,7 @@
bottomH = 34; bottomH = 34;
} }
_myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kTopHeight + 13 * k6Scale, kScreenWidth, kScreenHeight - bottomH - 49 - kTopHeight - 13 * k6Scale) style:UITableViewStyleGrouped]; _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kTopHeight + 13 * k6Scale, kScreenWidth, kScreenHeight - bottomH - 49 - kTopHeight - 13 * k6Scale) style:UITableViewStyleGrouped];
// _myTableView.contentInset = UIEdgeInsetsMake(6 * k6Scale, 0, 0, 0);
_myTableView.delegate = self; _myTableView.delegate = self;
_myTableView.dataSource = self; _myTableView.dataSource = self;
......
// //
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
@property (nonatomic, strong) NSArray *balances; @property (nonatomic, strong) NSArray *balances;
/** 蓝牙未连接成功的情况下 保存socket发送的消息 */
@property (nonatomic, strong) NSMutableArray *tempData;
@end @end
...@@ -92,8 +93,8 @@ ...@@ -92,8 +93,8 @@
//初始化socket //初始化socket
self.clientSocket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; self.clientSocket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
//开始建立连接 //开始建立连接
[self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil]; // [self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil];
NSLog(@"😇😇😇😇😇😇 socket开始连接---%@", [ZXTool getTimeNow]); // NSLog(@"😇😇😇😇😇😇 socket开始连接---%@", [ZXTool getTimeNow]);
@weakify(self); @weakify(self);
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kSelf_help_start_timer object:nil] subscribeNext:^(id x) { [[[NSNotificationCenter defaultCenter] rac_addObserverForName:kSelf_help_start_timer object:nil] subscribeNext:^(id x) {
...@@ -129,7 +130,12 @@ ...@@ -129,7 +130,12 @@
} }
return _balances; return _balances;
} }
- (NSMutableArray *)tempData {
if (_tempData == nil) {
_tempData = [NSMutableArray new];
}
return _tempData;
}
- (void)setDefaultModel:(NSInteger)defaultModel { - (void)setDefaultModel:(NSInteger)defaultModel {
_defaultModel = defaultModel; _defaultModel = defaultModel;
if (_defaultModel == 1 || _defaultModel == 2) { if (_defaultModel == 1 || _defaultModel == 2) {
...@@ -380,6 +386,9 @@ ...@@ -380,6 +386,9 @@
return; return;
} }
NSLog(@"😇😇😇😇😇😇 开始搜索蓝牙---%@", [ZXTool getTimeNow]); NSLog(@"😇😇😇😇😇😇 开始搜索蓝牙---%@", [ZXTool getTimeNow]);
[self.tempData removeAllObjects];
[self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self sendMessage:[NSString stringWithFormat:@"{<%@>}", self.currentPeripheralName]]; [self sendMessage:[NSString stringWithFormat:@"{<%@>}", self.currentPeripheralName]];
self.isServiceCut = NO;//标记为开始 self.isServiceCut = NO;//标记为开始
self.startDrink.enabled = NO;//按钮不可点击 self.startDrink.enabled = NO;//按钮不可点击
...@@ -387,15 +396,21 @@ ...@@ -387,15 +396,21 @@
//开始搜索设备的时候触发 //开始搜索设备的时候触发
[self checkBluetoothConectStatus]; [self checkBluetoothConectStatus];
[SVProgressHUD showWithStatus:@"蓝牙连接中..."]; [SVProgressHUD showWithStatus:@"蓝牙连接中..."];
});
} }
#pragma mark - ==========点击了开始按钮 5s后检测蓝牙连接状态========== #pragma mark - ==========点击了开始按钮 5s后检测蓝牙连接状态==========
- (void) checkBluetoothConectStatus { - (void) checkBluetoothConectStatus {
// [ZXTool showLoadingAnimation]; // [ZXTool showLoadingAnimation];
NSInteger times = 5; NSInteger times = 0.2;
if (self.clientSocket.isConnected == NO) {
times += 0.5;
[self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil];
}
if (self.currentBluetooth.isOnlyBluetooth) { if (self.currentBluetooth.isOnlyBluetooth) {
times = 10; times = 5;
} }
//5s之后查询蓝牙连接状态 //5s之后查询蓝牙连接状态
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(times * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(times * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
...@@ -484,6 +499,8 @@ ...@@ -484,6 +499,8 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
ZXBluetoothModel *m = [ZXBluetoothModel mj_objectWithKeyValues:common.data]; ZXBluetoothModel *m = [ZXBluetoothModel mj_objectWithKeyValues:common.data];
[ZXBluetoothModel clearTable]; [ZXBluetoothModel clearTable];
self.currentPeripheralName = m.code;
[self sendDeviceInfoToSocketByTimes:3];
[m save]; [m save];
self.numberLabel.text = [NSString stringWithFormat:@"设备名称:%@", m.code]; self.numberLabel.text = [NSString stringWithFormat:@"设备名称:%@", m.code];
self.addressLabel.text = [NSString stringWithFormat:@"设备地址:%@", m.position]; self.addressLabel.text = [NSString stringWithFormat:@"设备地址:%@", m.position];
...@@ -768,7 +785,7 @@ ...@@ -768,7 +785,7 @@
//初始化socket //初始化socket
self.clientSocket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; self.clientSocket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
} }
if (self.isSocketConnected == NO) { if (self.isSocketConnected == NO || self.clientSocket.isConnected == NO) {
//开始建立连接 //开始建立连接
[self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil]; [self.clientSocket connectToHost:[kUserDefaults objectForKey:@"BATHSocketUrl"] onPort:[[kUserDefaults objectForKey:@"BATHSocketPort"] integerValue] viaInterface:nil withTimeout:-1 error:nil];
} }
...@@ -831,6 +848,8 @@ ...@@ -831,6 +848,8 @@
#pragma mark - ==========scoket========== #pragma mark - ==========scoket==========
// 发送空消息 // 发送空消息
- (void)sendMessage:(NSString *) msg { - (void)sendMessage:(NSString *) msg {
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding]; NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
// withTimeout -1 : 无穷大,一直等 // withTimeout -1 : 无穷大,一直等
// tag : 消息标记 // tag : 消息标记
...@@ -850,9 +869,10 @@ ...@@ -850,9 +869,10 @@
self.isSocketConnected = YES; self.isSocketConnected = YES;
NSLog(@"😇😇😇😇😇😇 socket连接成功---%@", [ZXTool getTimeNow]); NSLog(@"😇😇😇😇😇😇 socket连接成功---%@", [ZXTool getTimeNow]);
//断开重连的时候发送一下设备信息(预防一种场景是蓝牙连接成功了 但是socket没连接成功的情况) //断开重连的时候发送一下设备信息(预防一种场景是蓝牙连接成功了 但是socket没连接成功的情况)
if (self.currentPeripheralName && (self.selectedPeripheral && self.selectedPeripheral.state == CBPeripheralStateConnected)) {
[self sendMessage:[NSString stringWithFormat:@"{<%@>}", self.currentPeripheralName]]; [self sendMessage:[NSString stringWithFormat:@"{<%@>}", self.currentPeripheralName]];
} // if (self.currentPeripheralName && (self.selectedPeripheral && self.selectedPeripheral.state == CBPeripheralStateConnected)) {
// [self sendMessage:[NSString stringWithFormat:@"{<%@>}", self.currentPeripheralName]];
// }
[self.clientSocket readDataWithTimeout:- 1 tag:0]; [self.clientSocket readDataWithTimeout:- 1 tag:0];
} }
...@@ -872,11 +892,25 @@ ...@@ -872,11 +892,25 @@
NSLog(@"=============收到服务器返回的设备号"); NSLog(@"=============收到服务器返回的设备号");
} else { } else {
//发送给蓝牙 //发送给蓝牙
if (self.currentCharacteristic) {
if (data.length > 100) { if (data.length > 100) {
//超出100 过滤 发送空消息保持连接 return;
[self.selectedPeripheral writeValue:[@"[]" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.currentCharacteristic type:CBCharacteristicWriteWithResponse]; }
} else if (data.length > 20) { [self.tempData addObject:data];
[self sendSocketMsgToBluetooth];
}
}
#pragma mark - 发送消息给蓝牙
- (void) sendSocketMsgToBluetooth {
if (self.tempData.count == 0) {
return;
}
if (self.currentCharacteristic) {
NSData *data = self.tempData[0];//去第一个
if (data.length > 20) {
NSInteger temp = data.length % 20; NSInteger temp = data.length % 20;
NSInteger count = 0; NSInteger count = 0;
...@@ -898,7 +932,7 @@ ...@@ -898,7 +932,7 @@
} else { } else {
[self.selectedPeripheral writeValue:data forCharacteristic:self.currentCharacteristic type:CBCharacteristicWriteWithResponse]; [self.selectedPeripheral writeValue:data forCharacteristic:self.currentCharacteristic type:CBCharacteristicWriteWithResponse];
} }
} [self.tempData removeObject:data];
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment