-
-
Notifications
You must be signed in to change notification settings - Fork 845
Add support for iOS Local Network permission #687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@interface LocalNetworkPrivacy : NSObject | ||
|
||
- (void)checkAccessState:(void (^)(BOOL))completion; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#import <UIKit/UIKit.h> | ||
#import "LocalNetworkPrivacy.h" | ||
|
||
@interface LocalNetworkPrivacy () <NSNetServiceDelegate> | ||
|
||
@property (nonatomic) NSNetService *service; | ||
@property (nonatomic) void (^completion)(BOOL); | ||
@property (nonatomic) NSTimer *timer; | ||
@property (nonatomic) BOOL publishing; | ||
|
||
@end | ||
|
||
@implementation LocalNetworkPrivacy | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
self.service = [[NSNetService alloc] initWithDomain:@"local." type:@"_lnp._tcp." name:@"LocalNetworkPrivacy" port:1100]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[self.service stop]; | ||
} | ||
|
||
- (void)checkAccessState:(void (^)(BOOL))completion { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this as reliable as:
|
||
self.completion = completion; | ||
|
||
self.publishing = YES; | ||
self.service.delegate = self; | ||
[self.service publish]; | ||
|
||
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 repeats:NO block:^(NSTimer * _Nonnull timer) { | ||
[self.timer invalidate]; | ||
self.completion(NO); | ||
}]; | ||
} | ||
|
||
|
||
#pragma mark - NSNetServiceDelegate | ||
|
||
- (void)netServiceDidPublish:(NSNetService *)sender { | ||
[self.timer invalidate]; | ||
self.completion(YES); | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'json' | ||
package = JSON.parse(File.read('../../package.json')) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "Permission-LocalNetworkPrivacy" | ||
s.dependency "RNPermissions" | ||
|
||
s.version = package["version"] | ||
s.license = package["license"] | ||
s.summary = package["description"] | ||
s.authors = package["author"] | ||
s.homepage = package["homepage"] | ||
|
||
s.ios.deployment_target = "10.0" | ||
s.tvos.deployment_target = "11.0" | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not personally checked, but have you checked all APIs are actually available on ios and tvos? out of curiosity, are there any restrictions for ipados / macCatalyst or macos? (just thinking cross-platform, though it's not a strict requirement or anything) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't checked yet, just based the podspec on one of the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs of NetService it is available on all platforms - but it has been deprecated with no obvious replacement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's unfortunate. And you're right, no real guidance. You probably found this as well but the only thing I found was the lower level stuff here https://developer.apple.com/library/archive/samplecode/DNSSDObjects/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011371-Intro-DontLinkElementID_2 - everything links to it |
||
s.requires_arc = true | ||
|
||
s.source = { :git => package["repository"]["url"], :tag => s.version } | ||
s.source_files = "*.{h,m}" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import "RNPermissions.h" | ||
|
||
@interface RNPermissionHandlerLocalNetworkPrivacy : NSObject<RNPermissionHandler> | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#import "RNPermissionHandlerLocalNetworkPrivacy.h" | ||
#import "LocalNetworkPrivacy.h" | ||
|
||
@implementation RNPermissionHandlerLocalNetworkPrivacy | ||
|
||
+ (NSArray<NSString *> * _Nonnull)usageDescriptionKeys { | ||
return @[@"NSLocalNetworkUsageDescription"]; | ||
} | ||
|
||
+ (NSString * _Nonnull)handlerUniqueId { | ||
return @"ios.permission.LOCAL_NETWORK_PRIVACY"; | ||
} | ||
|
||
- (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve | ||
rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject { | ||
if (![RNPermissionsHelper isFlaggedAsRequested:[[self class] handlerUniqueId]]) { | ||
return resolve(RNPermissionStatusNotDetermined); | ||
} | ||
|
||
[self requestWithResolver:resolve rejecter:reject]; | ||
} | ||
|
||
- (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve | ||
rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject { | ||
[RNPermissionsHelper flagAsRequested:[[self class] handlerUniqueId]]; | ||
|
||
LocalNetworkPrivacy *local = [LocalNetworkPrivacy new]; | ||
[local checkAccessState:^(BOOL granted) { | ||
resolve(granted ? RNPermissionStatusAuthorized : RNPermissionStatusDenied); | ||
}]; | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.