|
@@ -25,8 +25,6 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
dispatch_source_t _searchTimer;
|
|
|
}
|
|
|
|
|
|
-@property (nonatomic, strong) NSMutableArray *currentDevices;
|
|
|
-
|
|
|
@property (nonatomic, strong) NSHashTable *listeners;
|
|
|
|
|
|
@end
|
|
@@ -83,7 +81,7 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
}
|
|
|
|
|
|
- (void)searchDeviceWithSearchTime:(int)searchTime
|
|
|
- timeBlock:(void(^)(NSInteger time,NSArray <NSDictionary *>*devices))timeBlock {
|
|
|
+ timeBlock:(void(^)(NSInteger time))timeBlock {
|
|
|
if (_upnpErrorCode == 0) {//开始搜索设备
|
|
|
[self checkBaseURL];
|
|
|
libupnp_BuildFilesList();
|
|
@@ -91,14 +89,13 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
} else {
|
|
|
[self startUpnp];
|
|
|
}
|
|
|
- [self.currentDevices removeAllObjects];
|
|
|
__block int count = searchTime +1;
|
|
|
_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_event_handler(_searchTimer, ^{
|
|
|
if (timeBlock) {
|
|
|
wd_main_queue(^{
|
|
|
- timeBlock(count,self.currentDevices);
|
|
|
+ timeBlock(count);
|
|
|
});
|
|
|
}
|
|
|
count --;
|
|
@@ -279,26 +276,12 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
[deviceDict setObject:@"Unknown" forKey:@"devNowArtist"];
|
|
|
}
|
|
|
[deviceDict setObject:@"1" forKey:@"isOnLine"];
|
|
|
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"deviceUUID = %@",array[1]];
|
|
|
- BOOL isExist = [self.currentDevices filteredArrayUsingPredicate:predicate].count;
|
|
|
- if (!isExist) {
|
|
|
- id<MKRWIFIDeviceManagerDelegate> obj;
|
|
|
- NSEnumerator *enumerator = [self.listeners objectEnumerator];
|
|
|
- while ((obj = [enumerator nextObject]) != nil) {
|
|
|
- wd_main_queue(^{
|
|
|
- if ([obj respondsToSelector:@selector(didSearchNewDevice:)]) {
|
|
|
- [obj didSearchNewDevice:deviceDict];
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- [self.currentDevices addObject:deviceDict];
|
|
|
- }
|
|
|
id<MKRWIFIDeviceManagerDelegate> obj;
|
|
|
NSEnumerator *enumerator = [self.listeners objectEnumerator];
|
|
|
while ((obj = [enumerator nextObject]) != nil) {
|
|
|
wd_main_queue(^{
|
|
|
- if ([obj respondsToSelector:@selector(currentDevicesChange:)]) {
|
|
|
- [obj currentDevicesChange:self.currentDevices];
|
|
|
+ if ([obj respondsToSelector:@selector(didSearchNewDevice:)]) {
|
|
|
+ [obj didSearchNewDevice:deviceDict];
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -464,13 +447,6 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
return resource;
|
|
|
}
|
|
|
|
|
|
-- (NSMutableArray *)currentDevices {
|
|
|
- if (!_currentDevices) {
|
|
|
- _currentDevices = [NSMutableArray array];
|
|
|
- }
|
|
|
- return _currentDevices;
|
|
|
-}
|
|
|
-
|
|
|
- (NSHashTable *)listeners{
|
|
|
if (!_listeners) {
|
|
|
_listeners = [NSHashTable weakObjectsHashTable];
|