-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDSBreadcrumb.mm
117 lines (89 loc) · 3.74 KB
/
DSBreadcrumb.mm
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#import "DSBreadcrumb.h"
#import "Global.h"
@implementation DSBreadcrumb
-(DSBreadcrumb*)initWithTitle:(NSString*)title andBundleId:(NSString*)bundleId {
[self setTitle:title];
[self setBundleId:bundleId];
[self setNavigationContext:[NSClassFromString(@"UISystemNavigationActionDestinationContext") systemNavigationActionContextWithTitle:title bundleId:bundleId]];
id switchAppBlock = ^ void () {
CPDistributedMessagingCenter *messagingCenter = [NSClassFromString(@"CPDistributedMessagingCenter") centerNamed:@"net.douglassoares.Breadcrumb"];
rocketbootstrap_distributedmessagingcenter_apply(messagingCenter);
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"shouldHideBreadcrumb"];
[messagingCenter sendMessageName:@"setShouldHideBreadcrumb" userInfo:userInfo];
LSApplicationWorkspace *work = [NSClassFromString(@"LSApplicationWorkspace") new];
[work openApplicationWithBundleID:_bundleId];
};
[self setHandler:switchAppBlock];
UISystemNavigationAction *tempNavigation = [[NSClassFromString(@"UISystemNavigationAction") alloc] init];
[self setNavigationAction:[[NSClassFromString(@"UISystemNavigationAction") alloc] initWithInfo:tempNavigation.info timeout:0 forResponseOnQueue:nil withHandler:switchAppBlock]];
[self.navigationAction.info _setObject:_navigationContext forSetting:1];
return self;
}
-(DSBreadcrumb*)initWithTitle:(NSString*)title andBundleId:(NSString*)bundleId withHandler:(id/*block*/)handler {
[self setTitle:title];
[self setBundleId:bundleId];
[self setNavigationContext:[NSClassFromString(@"UISystemNavigationActionDestinationContext") systemNavigationActionContextWithTitle:title bundleId:bundleId]];
DSBreadcrumb *context = self;
id switchAppBlock = ^ void () {
[handler invoke];
[context hideBreadcrumb];
};
[self setHandler:switchAppBlock];
UISystemNavigationAction *tempNavigation = [[NSClassFromString(@"UISystemNavigationAction") alloc] init];
[self setNavigationAction:[[NSClassFromString(@"UISystemNavigationAction") alloc] initWithInfo:tempNavigation.info timeout:0 forResponseOnQueue:nil withHandler:switchAppBlock]];
[self.navigationAction.info _setObject:_navigationContext forSetting:1];
return self;
}
-(DSBreadcrumb*)initWithVisibleBreadcrumb {
UISystemNavigationAction *currentBreadcrumb = [[UIApplication sharedApplication] _systemNavigationAction];
UISystemNavigationActionDestinationContext *currentDestinationContext = [[currentBreadcrumb info] objectForSetting:1];
[self setTitle:[currentDestinationContext title]];
[self setBundleId:[currentDestinationContext bundleId]];
[self setNavigationContext:currentDestinationContext];
return self;
}
-(NSString*)bundleId {
return _bundleId;
}
-(void)setBundleId:(NSString*)bundleId {
_bundleId = bundleId;
[_navigationContext setBundleId:bundleId];
}
-(NSString*)title {
return _title;
}
-(void)setTitle:(NSString*)title {
_title = title;
[_navigationContext setTitle:title];
}
-(id)handler {
return _handler;
}
-(void)setHandler:(id)handler {
_handler = handler;
}
-(UISystemNavigationActionDestinationContext*)navigationContext {
return _navigationContext;
}
-(void)setNavigationContext:(UISystemNavigationActionDestinationContext*)navigationContext{
_navigationContext = navigationContext;
}
-(UISystemNavigationAction*)navigationAction {
return _navigationAction;
}
-(void)setNavigationAction:(UISystemNavigationAction*)navigationAction{
_navigationAction = navigationAction;
}
-(bool)isShowing {
if ([[UIApplication sharedApplication] _systemNavigationAction])
return YES;
else
return NO;
}
-(void)showBreadcrumb {
[[UIApplication sharedApplication] _setSystemNavigationAction:_navigationAction];
}
-(void)hideBreadcrumb {
[[UIApplication sharedApplication] _setSystemNavigationAction:nil];
}
@end