@@ -7,14 +7,11 @@ @interface LocalNetworkPrivacy () <NSNetServiceDelegate>
7
7
@property (nonatomic ) void (^completion)(BOOL );
8
8
@property (nonatomic ) NSTimer *timer;
9
9
@property (nonatomic ) BOOL publishing;
10
- @property (class , nonatomic ) OptionalBool granted;
11
10
12
11
@end
13
12
14
13
@implementation LocalNetworkPrivacy
15
14
16
- static OptionalBool granted = OptionalBoolNone;
17
-
18
15
- (instancetype )init {
19
16
if (self = [super init ]) {
20
17
self.service = [[NSNetService alloc ] initWithDomain: @" local." type: @" _lnp._tcp." name: @" LocalNetworkPrivacy" port: 1100 ];
@@ -26,36 +23,23 @@ - (void)dealloc {
26
23
[self .service stop ];
27
24
}
28
25
29
- + (OptionalBool)authorizationStatus {
30
- return granted;
31
- }
32
-
33
26
- (void )checkAccessState : (void (^)(BOOL ))completion {
34
27
self.completion = completion;
35
28
36
- self.timer = [NSTimer scheduledTimerWithTimeInterval: 2 repeats: YES block: ^(NSTimer * _Nonnull timer) {
37
- if (UIApplication.sharedApplication .applicationState != UIApplicationStateActive) {
38
- return ;
39
- }
40
-
41
- if (self.publishing ) {
42
- granted = OptionalBoolNo;
43
- [self .timer invalidate ];
44
- self.completion (NO );
45
- }
46
- else {
47
- self.publishing = YES ;
48
- self.service .delegate = self;
49
- [self .service publish ];
50
- }
29
+ self.publishing = YES ;
30
+ self.service .delegate = self;
31
+ [self .service publish ];
32
+
33
+ self.timer = [NSTimer scheduledTimerWithTimeInterval: 2 repeats: NO block: ^(NSTimer * _Nonnull timer) {
34
+ [self .timer invalidate ];
35
+ self.completion (NO );
51
36
}];
52
37
}
53
38
54
39
55
40
#pragma mark - NSNetServiceDelegate
56
41
57
42
- (void )netServiceDidPublish : (NSNetService *)sender {
58
- granted = OptionalBoolYes;
59
43
[self .timer invalidate ];
60
44
self.completion (YES );
61
45
}
0 commit comments