-
Notifications
You must be signed in to change notification settings - Fork 2
/
AirdropDelegate.m
39 lines (30 loc) · 1.11 KB
/
AirdropDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "AirdropDelegate.h"
@interface AirdropDelegate () <NSSharingServiceDelegate>
@end
@implementation AirdropDelegate
- (void)setUrlName:(NSString *)url {
_urlName = url;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSString *sharingServiceName = NSSharingServiceNameSendViaAirDrop;
NSSharingService *sharingService = [NSSharingService sharingServiceNamed:sharingServiceName];
sharingService.delegate = self;
NSMutableArray *mutableItems = [NSMutableArray array];
NSString *escapedUrl = [_urlName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:escapedUrl];
[mutableItems addObject:url];
[sharingService performWithItems:mutableItems];
}
#pragma mark - NSSharingServiceDelegate
- (void)sharingService:(NSSharingService *)sharingService
didShareItems:(NSArray *)items
{
exit(EXIT_SUCCESS);
}
- (void)sharingService:(NSSharingService *)sharingService
didFailToShareItems:(NSArray *)items
error:(NSError *)error
{
exit(EXIT_FAILURE);
}
@end