Skip to content

Commit a51f6f1

Browse files
committed
Added URI call to navigate from widget to the main app
1 parent 1886c15 commit a51f6f1

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

BitStore/AppDelegate.m

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "Address.h"
1414
#import "URI.h"
1515
#import "SendNavigationController.h"
16+
#import "ReceiveNavigationController.h"
1617
#import "AppStart.h"
1718

1819
@implementation AppDelegate
@@ -48,10 +49,24 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
4849
}
4950

5051
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
51-
URI* uri = [[URI alloc] initWithString:url.description];
52-
SendNavigationController* vc = [[SendNavigationController alloc] initWithAddress:uri.address amount:uri.amount];
53-
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
54-
return YES;
52+
BOOL opened = NO;
53+
if ([url.scheme isEqualToString:@"bitcoin"]) {
54+
URI* uri = [[URI alloc] initWithString:url.description];
55+
SendNavigationController* vc = [[SendNavigationController alloc] initWithAddress:uri.address amount:uri.amount];
56+
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
57+
opened = YES;
58+
} else if ([url.scheme isEqualToString:@"bitstore"]) {
59+
if ([url.lastPathComponent isEqualToString:@"send"]) {
60+
SendNavigationController* vc = [[SendNavigationController alloc] init];
61+
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
62+
opened = YES;
63+
} else if ([url.lastPathComponent isEqualToString:@"receive"]) {
64+
ReceiveNavigationController* vc = [[ReceiveNavigationController alloc] init];
65+
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
66+
opened = YES;
67+
}
68+
}
69+
return opened;
5570
}
5671

5772
@end

BitStore/BitStore-Info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<key>CFBundleURLSchemes</key>
2929
<array>
3030
<string>bitcoin</string>
31+
<string>bitstore</string>
3132
</array>
3233
</dict>
3334
</array>

BitStoreToday/TodayViewController.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ - (void)viewWillAppear:(BOOL)animated {
5050
[sendButton setSelectedTintColor:buttonSelectedColor];
5151
CGSize sendSize = [sendTitle sizeWithAttributes:@{NSFontAttributeName:sendButton.titleLabel.font}];
5252
sendButton.frame = CGRectMake(self.view.bounds.size.width - sendSize.width - 30, 7, sendSize.width, 50);
53+
[sendButton addTarget:self action:@selector(actionSend:) forControlEvents:UIControlEventTouchUpInside];
5354
[self.view addSubview:sendButton];
5455

5556

@@ -60,9 +61,20 @@ - (void)viewWillAppear:(BOOL)animated {
6061
[receiveButton setSelectedTintColor:buttonSelectedColor];
6162
CGSize receiveSize = [receiveTitle sizeWithAttributes:@{NSFontAttributeName:receiveButton.titleLabel.font}];
6263
receiveButton.frame = CGRectMake(self.view.bounds.size.width - receiveSize.width - sendSize.width - 60, 12, receiveSize.width, 50);
64+
[receiveButton addTarget:self action:@selector(actionReceive:) forControlEvents:UIControlEventTouchUpInside];
6365
[self.view addSubview:receiveButton];
6466
}
6567

68+
- (void)actionSend:(id)sender {
69+
NSURL* url = [[NSURL alloc] initWithScheme:@"bitstore" host:nil path:@"/send"];
70+
[self.extensionContext openURL:url completionHandler:nil];
71+
}
72+
73+
- (void)actionReceive:(id)sender {
74+
NSURL* url = [[NSURL alloc] initWithScheme:@"bitstore" host:nil path:@"/receive"];
75+
[self.extensionContext openURL:url completionHandler:nil];
76+
}
77+
6678
- (void)updatePriceLabel {
6779
SharedUser* user = [self user];
6880
if (user.cachedPrice) {

0 commit comments

Comments
 (0)