修复设备连接问题
This commit is contained in:
parent
347a774be9
commit
6855052852
|
|
@ -17,7 +17,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<string>5.0.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleURLTypes</key>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<string>10.1.5</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
|
|||
-(void)checkWiFi{
|
||||
NSDictionary *ifs = [self getSSIDInfo];
|
||||
NSString *wifiName = [ifs objectForKey:@"SSID"];
|
||||
if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) {
|
||||
if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound) {
|
||||
//wifi正确,则尝试连接设备
|
||||
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
|
||||
connecting.ssid = self.ssid;
|
||||
|
|
@ -114,20 +114,19 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
|
|||
[self.view makeToast:@"WiFi名称不匹配,请重试"];
|
||||
}
|
||||
}
|
||||
- (id)getSSIDInfo
|
||||
- (NSDictionary *)getSSIDInfo
|
||||
{
|
||||
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
|
||||
id info = nil;
|
||||
for (NSString *ifnam in ifs) {
|
||||
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
|
||||
if (info && [info count]) {
|
||||
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
NSDictionary *SSIDInfo;
|
||||
for (NSString *interfaceName in interfaceNames) {
|
||||
SSIDInfo = CFBridgingRelease(
|
||||
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
|
||||
BOOL isNotEmpty = (SSIDInfo.count > 0);
|
||||
if (isNotEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return info ;
|
||||
return SSIDInfo;
|
||||
}
|
||||
//即将进入前台
|
||||
-(void)viewWillEnterForeground:(NSNotification *)noti{
|
||||
|
|
|
|||
|
|
@ -211,20 +211,19 @@ Strong UIButton *nextBtn;
|
|||
}
|
||||
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library
|
||||
//获取WiFi信息
|
||||
- (id)getSSIDInfo
|
||||
- (NSDictionary *)getSSIDInfo
|
||||
{
|
||||
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
|
||||
id info = nil;
|
||||
for (NSString *ifnam in ifs) {
|
||||
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
|
||||
if (info && [info count]) {
|
||||
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
NSDictionary *SSIDInfo;
|
||||
for (NSString *interfaceName in interfaceNames) {
|
||||
SSIDInfo = CFBridgingRelease(
|
||||
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
|
||||
BOOL isNotEmpty = (SSIDInfo.count > 0);
|
||||
if (isNotEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return info ;
|
||||
return SSIDInfo;
|
||||
}
|
||||
#pragma mark --buttonClick
|
||||
-(void)nextBtnClick:(UIButton *)sender{
|
||||
|
|
|
|||
|
|
@ -53,26 +53,26 @@ Copy NSString *deviceId;
|
|||
}];
|
||||
[self.progressView updatePercent:100 animation:YES];
|
||||
[self.progressView endProgressWithString:@"设备连接中..."];
|
||||
self.HUD.labelText = @"正在绑定设备";
|
||||
|
||||
if ( [GWP2PClient sharedClient].linkStatus==P2PLinkStatusOK) {
|
||||
[self connectDevice];
|
||||
}else{
|
||||
UserModel *model=[dataContorl getUserInfo];
|
||||
[self loginGewellWith:model];
|
||||
}
|
||||
// self.HUD.labelText = @"正在绑定设备";
|
||||
//
|
||||
// if ( [GWP2PClient sharedClient].linkStatus==P2PLinkStatusOK) {
|
||||
// [self connectDevice];
|
||||
// }else{
|
||||
// UserModel *model=[dataContorl getUserInfo];
|
||||
// [self loginGewellWith:model];
|
||||
// }
|
||||
|
||||
//传入设备要连接的wifi名称和密码
|
||||
// [self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
|
||||
[self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
|
||||
// // Do any additional setup after loading the view.
|
||||
//
|
||||
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
|
||||
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
|
||||
|
||||
}
|
||||
//AP模式配网
|
||||
-(void)connectDevice{
|
||||
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
||||
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
|
||||
//已经连接到设备,此处回调之后,会断开热点,重新连接到路由器wifi
|
||||
NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport);
|
||||
self.HUD.labelText = @"设备WiFi配置成功,之后会断开设备热点,连接设备到路由器";
|
||||
|
|
@ -242,7 +242,7 @@ Copy NSString *deviceId;
|
|||
}
|
||||
|
||||
#pragma mark - IFishHotpotUDPHelperDelegate
|
||||
|
||||
//这里是连接到设备的路由器之后的回调方法
|
||||
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
|
||||
self.ssid = backModel.senderMacAddress;
|
||||
[self.view resignFirstResponder];
|
||||
|
|
@ -255,10 +255,12 @@ Copy NSString *deviceId;
|
|||
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = nil;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
|
||||
//这里需要连接到之前的路由器,才能绑定设备到
|
||||
self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startBinding) userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)startBinding {
|
||||
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue