aboutsummaryrefslogtreecommitdiffstats
path: root/CopyMailto/DefaultURLHandler.m
blob: 123ad7b73fa9d24aa9f778fac3e3d9bd5cc6b261 (plain)
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
//
//  DefaultURLHandler.m
//  CopyMailto
//
//  Created by tw on 9/5/18.
//  Copyright © 2018 tw. All rights reserved.
//

#import "DefaultURLHandler.h"

@implementation DefaultURLHandler

+ (OSStatus)setDefaultURLHandler {
    CFStringRef scheme = (CFStringRef)@"mailto";
    CFStringRef bundle_identifier = (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
    NSLog(@"%@", scheme);
    NSLog(@"%@", bundle_identifier);

    OSStatus status = LSSetDefaultHandlerForURLScheme(scheme, bundle_identifier);
    NSLog(@"%d", status);

    CFRelease(scheme);

    return status;
}

+ (void)saveDefaultURLHandler {
    CFStringRef mailto = (CFStringRef)@"mailto";
    CFStringRef bundle_identifier = LSCopyDefaultHandlerForURLScheme(mailto);
    NSLog(@"%@", bundle_identifier);

    CFRelease(mailto);
    CFRelease(bundle_identifier);
}

@end