|
9 | 9 |
|
10 | 10 | NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect = @"xp2disconnect"; //p2p通道断开 |
11 | 11 | NSNotificationName const TIoTCoreXP2PBridgeNotificationReady = @"xp2preconnect"; //app本地已ready,表示探测完成,可以发起请求了 |
| 12 | +NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError = @"xp2detecterror"; //探测失败,网络不正常表示探测完成,可以发起请求了 |
12 | 13 | NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg = @"XP2PTypeDeviceMsgArrived"; //收到设备端的请求数据 |
13 | 14 | NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd = @"XP2PTypeStreamEnd"; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流 |
14 | 15 |
|
@@ -54,11 +55,16 @@ - (void)cancelTimer; |
54 | 55 |
|
55 | 56 | NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@""; |
56 | 57 |
|
57 | | - if (type == XP2PTypeDisconnect || type == XP2PTypeDetectError) { |
| 58 | + if (type == XP2PTypeDisconnect) { |
58 | 59 | [[TIoTCoreXP2PBridge sharedInstance] cancelTimer]; |
59 | 60 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
60 | 61 | [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDisconnect object:nil userInfo:@{@"id": DeviceName}]; |
61 | 62 | }); |
| 63 | + }else if (type == XP2PTypeDetectError) { |
| 64 | + [[TIoTCoreXP2PBridge sharedInstance] cancelTimer]; |
| 65 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 66 | + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDetectError object:nil userInfo:@{@"id": DeviceName}]; |
| 67 | + }); |
62 | 68 | }else if (type == XP2PTypeDetectReady) { |
63 | 69 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
64 | 70 | [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationReady object:nil userInfo:@{@"id": DeviceName}]; |
@@ -209,21 +215,23 @@ - (XP2PErrCode)startAppWith:(NSString *)sec_id sec_key:(NSString *)sec_key pro_i |
209 | 215 | //1.配置IOT_P2P SDK |
210 | 216 | self.dev_name = dev_name; |
211 | 217 | setQcloudApiCred([sec_id UTF8String], [sec_key UTF8String]); //正式版app发布时候需要去掉,避免泄露secretid和secretkey,此处仅为演示 |
212 | | - int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String); |
| 218 | + int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, 5); |
213 | 219 | setDeviceXp2pInfo(dev_name.UTF8String, xp2pinfo.UTF8String); |
214 | 220 | return (XP2PErrCode)ret; |
215 | 221 | } |
216 | 222 |
|
217 | 223 |
|
218 | | - |
219 | 224 | - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name { |
| 225 | + return [self startAppWith:pro_id dev_name:dev_name sensor_timeout:5]; |
| 226 | +} |
| 227 | +- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name sensor_timeout:(int)sensor_timeout{ |
220 | 228 | // setStunServerToXp2p("11.11.11.11", 111); |
221 | 229 | //注册回调 |
222 | 230 | setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle); |
223 | 231 |
|
224 | 232 | //1.配置IOT_P2P SDK |
225 | 233 | self.dev_name = dev_name; |
226 | | - int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String); |
| 234 | + int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, sensor_timeout); |
227 | 235 | return (XP2PErrCode)ret; |
228 | 236 | } |
229 | 237 |
|
|
0 commit comments