-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUserActivity.m
86 lines (73 loc) · 3 KB
/
UserActivity.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
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
#import "UserActivity.h"
@import CoreSpotlight;
@import MapKit;
@implementation UserActivity
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(
createActivity:(NSString *)activityType
eligibleForSearch:(BOOL)eligibleForSearch
eligibleForPublicIndexing:(BOOL)eligibleForPublicIndexing
eligibleForHandoff:(BOOL)eligibleForHandoff
title:(NSString *)title
webpageURL:(NSString *)webpageURL
userInfo:(NSDictionary *)userInfo
locationInfo:(NSDictionary *)locationInfo
supportsNavigation:(BOOL)supportsNavigation
supportsPhoneCall:(BOOL)supportsPhoneCall
phoneNumber:(NSString *)phoneNumber
description:(NSString *)description
thumbnailURL:(NSString *)thumbnailURL
identifier:(NSString *)identifier
)
{
// Your implementation here
if([NSUserActivity class] && [NSUserActivity instancesRespondToSelector:@selector(setEligibleForSearch:)]){
if(!self.lastUserActivities) {
self.lastUserActivities = [@[] mutableCopy];
}
NSUserActivity* activity = [[NSUserActivity alloc] initWithActivityType:activityType];
activity.eligibleForSearch = eligibleForSearch;
activity.eligibleForPublicIndexing = eligibleForPublicIndexing;
activity.eligibleForHandoff = eligibleForHandoff;
activity.title = title;
activity.webpageURL = [NSURL URLWithString:webpageURL];
activity.userInfo = userInfo;
activity.keywords = [NSSet setWithArray:@[title]];
if ([CSSearchableItemAttributeSet class]) {
CSSearchableItemAttributeSet *contentSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:activityType];
contentSet.title = title;
contentSet.URL = [NSURL URLWithString:webpageURL];
if (description) {
contentSet.contentDescription = description;
}
if (thumbnailURL) {
contentSet.thumbnailURL = [NSURL fileURLWithPath:thumbnailURL];
}
if (identifier) {
contentSet.identifier = identifier;
}
if (phoneNumber) {
contentSet.phoneNumbers = @[phoneNumber];
}
contentSet.supportsNavigation = @(supportsNavigation);
contentSet.supportsPhoneCall = @(supportsPhoneCall);
activity.contentAttributeSet = contentSet;
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if ([activity respondsToSelector:@selector(mapItem)] && [locationInfo objectForKey:@"lat"] && [locationInfo objectForKey:@"lon"]) {
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([locationInfo[@"lat"] doubleValue], [locationInfo[@"lon"] doubleValue])];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
mapItem.name = title;
mapItem.url = [NSURL URLWithString:webpageURL];
activity.mapItem = mapItem;
}
#endif
self.lastUserActivity = activity;
[self.lastUserActivities addObject:activity];
[activity becomeCurrent];
if (self.lastUserActivities.count > 5) {
[self.lastUserActivities removeObjectAtIndex:0];
}
}
}
@end