尹永奇 пре 5 година
родитељ
комит
c94d106839

+ 22 - 0
Example/MKRRadioManager/MKRViewController.m

@@ -10,6 +10,7 @@
 #import "MKRPlayControlViewController.h"
 #import <MKRRadioManager/MKRAVPlayer.h>
 #import <YYCategory/NSString+Utilities.h>
+#import <NSHashTable+MKRRadioManagerAdd.h>
 
 @interface MKRViewController ()
 
@@ -19,6 +20,8 @@
 
 @property (nonatomic, strong) MKRAVPlayer *player;
 
+@property (nonatomic, strong) NSHashTable *hashTable;
+
 @end
 
 @implementation MKRViewController
@@ -32,11 +35,19 @@
     [_MKRWIFIDeviceManager searchDeviceWithSearchTime:20 timeBlock:^(NSInteger time) {
         [self.tableView reloadData];
     }];
+    
 }
 
 - (void)viewDidLoad
 {
     [super viewDidLoad];
+    
+    [self.hashTable addObject:self];
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
+        for (NSInteger i = 0; i<10; i++) {
+            [self.hashTable makeObjectsPerformSelectorWithObjectsOnMainThread:@selector(testMethod)];
+        }
+    });
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@@ -56,6 +67,10 @@
     [self.navigationController pushViewController:vc animated:YES];
 }
 
+- (void)testMethod{
+    MKRLog(@"测试方法");
+}
+
 - (NSMutableArray *)dataSource {
     if (!_dataSource) {
         _dataSource = [NSMutableArray array];
@@ -63,4 +78,11 @@
     return _dataSource;
 }
 
+- (NSHashTable *)hashTable{
+    if (!_hashTable) {
+        _hashTable = [NSHashTable weakObjectsHashTable];
+    }
+    return _hashTable;
+}
+
 @end

+ 7 - 7
MKRRadioManager/Classes/MKRRadioManager/Category/NSHashTable+MKRRadioManagerAdd.m

@@ -47,14 +47,14 @@
                 if (!sig) {
                     [obj doesNotRecognizeSelector:sel];
                 }
+                NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
+                if (!invocation) {
+                    [obj doesNotRecognizeSelector:sel];
+                }
+                [invocation setTarget:obj];
+                [invocation setSelector:sel];
+                [self setInv:invocation withSig:sig andArgs:args];
                 dispatch_async(dispatch_get_main_queue(), ^{
-                    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
-                    if (!invocation) {
-                        [obj doesNotRecognizeSelector:sel];
-                    }
-                    [invocation setTarget:obj];
-                    [invocation setSelector:sel];
-                    [self setInv:invocation withSig:sig andArgs:args];
                     [invocation invoke];
                 });