Browse Source

版本升级维护

yyqxiaoyin 5 years ago
parent
commit
5f2de46ff4

+ 3 - 1
MKRRadioManager/Classes/MKRRadioManager/Category/UIDevice+MKRRadioManagerAdd.h

@@ -10,4 +10,6 @@
 
 
 + (NSString *)currentDeviceInfo;
 + (NSString *)currentDeviceInfo;
 
 
-@end
++ (NSString *)currentSSID;
+
+@end

+ 14 - 0
MKRRadioManager/Classes/MKRRadioManager/Category/UIDevice+MKRRadioManagerAdd.m

@@ -7,6 +7,7 @@
 #include <net/if.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_dl.h>
 #include <mach/machine.h>
 #include <mach/machine.h>
+#import <SystemConfiguration/CaptiveNetwork.h>
 
 
 #define IOS6_7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 6.0
 #define IOS6_7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 6.0
 
 
@@ -127,4 +128,17 @@
     return macAddressString;
     return macAddressString;
 }
 }
 
 
++ (NSString *)currentSSID{
+    NSString *ssid = @"Not Found";
+    CFArrayRef myArray = CNCopySupportedInterfaces();
+    if (myArray != nil) {
+        CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
+        if (myDict != nil) {
+            NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
+            ssid = [dict valueForKey:@"SSID"];
+        }
+    }
+    return ssid;
+}
+
 @end
 @end

+ 3 - 0
MKRRadioManager/Classes/MKRRadioManager/MKRWIFIDeviceManager/MKRWIFIDeviceManager.h

@@ -37,6 +37,9 @@
  */
  */
 - (NSInteger)startUpnp;
 - (NSInteger)startUpnp;
 
 
+/// 刷新upnp服务
+- (void)reloadUpnp;
+
 /**
 /**
  * 搜索设备
  * 搜索设备
  * @param searchTime 搜索时长
  * @param searchTime 搜索时长

+ 29 - 0
MKRRadioManager/Classes/MKRRadioManager/MKRWIFIDeviceManager/MKRWIFIDeviceManager.m

@@ -29,6 +29,9 @@ static inline void wd_playControl_queue(void (^block)(void)){
     int _upnpErrorCode;
     int _upnpErrorCode;
     NSMutableArray *_baseUrlArray;
     NSMutableArray *_baseUrlArray;
     dispatch_source_t _searchTimer;
     dispatch_source_t _searchTimer;
+    NSString *_ssid;
+    BOOL _shutDownUpnping;
+    BOOL _updateLocalResourceLock;
 }
 }
 
 
 @property (nonatomic, strong) NSHashTable *listeners;
 @property (nonatomic, strong) NSHashTable *listeners;
@@ -89,9 +92,34 @@ static inline void wd_playControl_queue(void (^block)(void)){
     return _upnpErrorCode;
     return _upnpErrorCode;
 }
 }
 
 
+- (void)reloadUpnp{
+    NSString *ssid = [UIDevice currentSSID];
+    if ([ssid isEqualToString:_ssid]) {
+        return;
+    }
+    if (_shutDownUpnping) {
+        return;
+    }
+    _ssid = ssid;
+    wd_playControl_queue(^{
+        _shutDownUpnping = YES;
+        libupnp_StopBuildFilesList();
+        int exitCount = 0;
+        while (_updateLocalResourceLock) {
+            exitCount++;
+            [NSThread sleepForTimeInterval:1.0];
+            if (exitCount > 10)
+                break;
+        }
+        _updateLocalResourceLock = NO;
+        [self searchDeviceWithSearchTime:20 timeBlock:nil];
+    });
+}
+
 - (void)searchDeviceWithSearchTime:(int)searchTime
 - (void)searchDeviceWithSearchTime:(int)searchTime
                          timeBlock:(void(^)(NSInteger time))timeBlock {
                          timeBlock:(void(^)(NSInteger time))timeBlock {
     wd_playControl_queue(^{
     wd_playControl_queue(^{
+        _updateLocalResourceLock = YES;
         if (_upnpErrorCode != 0) {
         if (_upnpErrorCode != 0) {
             if ([self startUpnp] == 0) {
             if ([self startUpnp] == 0) {
                 [self checkBaseURL];
                 [self checkBaseURL];
@@ -100,6 +128,7 @@ static inline void wd_playControl_queue(void (^block)(void)){
         }
         }
         libupnp_SearchDevice(20);
         libupnp_SearchDevice(20);
     });
     });
+    _ssid = [UIDevice currentSSID];
     __block int count = searchTime +1;
     __block int count = searchTime +1;
     _searchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
     _searchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
     dispatch_source_set_timer(_searchTimer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
     dispatch_source_set_timer(_searchTimer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);