Procházet zdrojové kódy

版本升级维护

尹永奇 před 5 roky
rodič
revize
2b17f69fd9

+ 6 - 0
Example/MKRRadioManager.xcodeproj/project.pbxproj

@@ -23,6 +23,7 @@
 		6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
 		71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; };
 		873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
+		BA7A1D5E245816A300E48A70 /* MKRTestObject.m in Sources */ = {isa = PBXBuildFile; fileRef = BA7A1D5D245816A300E48A70 /* MKRTestObject.m */; };
 		BAD6DE83226708F70095069D /* MKRPlayControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BAD6DE82226708F70095069D /* MKRPlayControlViewController.m */; };
 		EA19B331230A354400BFA3D2 /* MKRRadioManager in Resources */ = {isa = PBXBuildFile; fileRef = EA19B330230A354400BFA3D2 /* MKRRadioManager */; };
 		F0C80BB9A91EABEC95F33C37 /* libPods-MKRRadioManager_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A891D43341CE97393A3100E5 /* libPods-MKRRadioManager_Example.a */; };
@@ -68,6 +69,8 @@
 		A891D43341CE97393A3100E5 /* libPods-MKRRadioManager_Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MKRRadioManager_Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
 		ABE922AAA9D41BC767AB86F0 /* MKRRadioManager.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MKRRadioManager.podspec; path = ../MKRRadioManager.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
 		AE2937E497D08BF5EB2A50DA /* libPods-MKRRadioManager_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MKRRadioManager_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
+		BA7A1D5C245816A300E48A70 /* MKRTestObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKRTestObject.h; sourceTree = "<group>"; };
+		BA7A1D5D245816A300E48A70 /* MKRTestObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKRTestObject.m; sourceTree = "<group>"; };
 		BAD6DE81226708F70095069D /* MKRPlayControlViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKRPlayControlViewController.h; sourceTree = "<group>"; };
 		BAD6DE82226708F70095069D /* MKRPlayControlViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKRPlayControlViewController.m; sourceTree = "<group>"; };
 		EA19B330230A354400BFA3D2 /* MKRRadioManager */ = {isa = PBXFileReference; lastKnownFileType = folder; name = MKRRadioManager; path = ../../MKRRadioManager/Classes/MKRRadioManager; sourceTree = "<group>"; };
@@ -148,6 +151,8 @@
 				71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */,
 				6003F5A8195388D20070C39A /* Images.xcassets */,
 				6003F594195388D20070C39A /* Supporting Files */,
+				BA7A1D5C245816A300E48A70 /* MKRTestObject.h */,
+				BA7A1D5D245816A300E48A70 /* MKRTestObject.m */,
 			);
 			name = "Example for MKRRadioManager";
 			path = MKRRadioManager;
@@ -358,6 +363,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				BA7A1D5E245816A300E48A70 /* MKRTestObject.m in Sources */,
 				6003F59E195388D20070C39A /* MKRAppDelegate.m in Sources */,
 				BAD6DE83226708F70095069D /* MKRPlayControlViewController.m in Sources */,
 				6003F5A7195388D20070C39A /* MKRViewController.m in Sources */,

+ 15 - 0
Example/MKRRadioManager/MKRTestObject.h

@@ -0,0 +1,15 @@
+//
+//  MKRTestObject.h
+//  MKRRadioManager_Example
+//
+//  Created by 尹永奇 on 2020/4/28.
+//  Copyright © 2020 yyqxiaoyin. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface MKRTestObject : NSObject
+
+- (void)testMethod:(NSString *)string;
+
+@end

+ 17 - 0
Example/MKRRadioManager/MKRTestObject.m

@@ -0,0 +1,17 @@
+//
+//  MKRTestObject.m
+//  MKRRadioManager_Example
+//
+//  Created by 尹永奇 on 2020/4/28.
+//  Copyright © 2020 yyqxiaoyin. All rights reserved.
+//
+
+#import "MKRTestObject.h"
+
+@implementation MKRTestObject
+
+- (void)testMethod:(NSString *)string{
+    NSLog(@"%s---%@",__func__,string);
+}
+
+@end

+ 21 - 6
Example/MKRRadioManager/MKRViewController.m

@@ -11,6 +11,7 @@
 #import <MKRRadioManager/MKRAVPlayer.h>
 #import <YYCategory/NSString+Utilities.h>
 #import <NSHashTable+MKRRadioManagerAdd.h>
+#import "MKRTestObject.h"
 
 @interface MKRViewController ()
 
@@ -22,10 +23,18 @@
 
 @property (nonatomic, strong) NSHashTable *hashTable;
 
+@property (nonatomic, strong) NSMutableArray *array;
+
 @end
 
 @implementation MKRViewController
 
+- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        [self.hashTable makeObjectsPerformSelectorWithObjectsOnMainThread:@selector(testMethod:),@"hello"];
+    });
+}
+
 - (IBAction)refresh:(UIBarButtonItem *)sender {
     [self.dataSource removeAllObjects];
     [self searchDevice];
@@ -42,12 +51,11 @@
 {
     [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)];
-        }
-    });
+    for (NSInteger i = 0; i<10; i++) {
+        MKRTestObject *obj = [[MKRTestObject alloc] init];
+        [self.array addObject:obj];
+        [self.hashTable addObject:obj];
+    }
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@@ -85,4 +93,11 @@
     return _hashTable;
 }
 
+- (NSMutableArray *)array{
+    if (!_array) {
+        _array = [NSMutableArray array];
+    }
+    return _array;
+}
+
 @end

+ 2 - 4
MKRRadioManager/Classes/MKRRadioManager/Category/NSHashTable+MKRRadioManagerAdd.m

@@ -54,10 +54,8 @@
                 [invocation setTarget:obj];
                 [invocation setSelector:sel];
                 [self setInv:invocation withSig:sig andArgs:args];
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [invocation invoke];
-                });
-                
+                [invocation retainArguments];
+                [invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:NO];
             }
         }
     }