-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-26312]: iOS 12 Expose new NSUserActivity APIs for Siri Intents #10288
Changes from 1 commit
2c05489
9fb9ed1
831f7d0
d4352e5
e2b7bc8
8b829e6
06789a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,29 @@ properties: | |
default: true | ||
availability: creation | ||
|
||
- name: eligibleForPrediction | ||
summary: | | ||
A Boolean value that determines whether Siri can suggest the user activity as a shortcut to the user. | ||
description: | | ||
To donate a user activity to Siri Shortcuts, set eligibleForPrediction to 'true' and make the | ||
user activity current. To make the user activity current, call the becomeCurrent method of activity. | ||
For more information, see https://developer.apple.com/documentation/sirikit/donating_shortcuts?language=objc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For more information, see [the Apple docs](https://developer.apple.com/documentation/sirikit/donating_shortcuts?language=objc). |
||
type: Boolean | ||
osver: {ios: {min: "12.0"}} | ||
default: false | ||
since: "7.4.0" | ||
availability: creation | ||
|
||
- name: persistentIdentifier | ||
summary: A value used to identify the user activity. | ||
description: | | ||
Set this property to a unique value that identifies the user activity so you can later delete it with | ||
Ti.App.iOS.UserActivity.deleteSavedUserActivitiesForPersistentIdentifiers method. | ||
type: String | ||
osver: {ios: {min: "12.0"}} | ||
since: "7.4.0" | ||
availability: creation | ||
|
||
- name: expirationDate | ||
summary: Absolute date after which the activity is no longer eligible to be indexed or handed off. | ||
description: | | ||
|
@@ -159,6 +182,33 @@ methods: | |
summary: Returns `true` if the device supports user activity. | ||
platforms: [iphone, ipad] | ||
osver: {ios: {min: "8.0"}} | ||
|
||
- name: deleteSavedUserActivitiesForPersistentIdentifiers | ||
summary: | | ||
Deletes user activities created by your app that have the specified persistent identifiers. | ||
description: | | ||
Ti.App.iOS.UserActivity.useractivitydeleted event get fired after deteting the user activities. | ||
Listen and wait for this event to fired to ensure that the system deletes the activities | ||
(or marks them for deletion). | ||
parameters: | ||
- name: persistentIdentifiers | ||
summary: Array of persistent identifiers of user activity. | ||
type: Array<String> | ||
platforms: [iphone, ipad] | ||
osver: {ios: {min: "12.0"}} | ||
since: "7.4.0" | ||
|
||
- name: deleteAllSavedUserActivities | ||
summary: | | ||
Deletes all user activities created by your app. | ||
description: | | ||
Ti.App.iOS.UserActivity.useractivitydeleted event get fired after deteting the user activities. | ||
Listen and wait for this event to fired to ensure that the system deletes the activities | ||
(or marks them for deletion). | ||
platforms: [iphone, ipad] | ||
osver: {ios: {min: "12.0"}} | ||
since: "7.4.0" | ||
|
||
events: | ||
- name: useractivitywillsave | ||
summary: | | ||
|
@@ -216,6 +266,15 @@ events: | |
summary: Dictionary object containing the userInfo data of the User Activity. | ||
type: Dictionary | ||
platforms: [iphone, ipad] | ||
|
||
- name: useractivitydeleted | ||
summary: | | ||
Fired when the user activity get deleted using Ti.App.iOS.UserActivity.deleteAllSavedUserActivities or | ||
Ti.App.iOS.UserActivity.deleteSavedUserActivitiesForPersistentIdentifiers method. | ||
platforms: [iphone, ipad] | ||
osver: {ios: {min: "12.0"}} | ||
since: "7.4.0" | ||
|
||
examples: | ||
- title: Creating a new UserActivity Example | ||
example: | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,19 @@ - (void)buildInitialActivity:(NSDictionary *)props | |
} | ||
} | ||
|
||
#if IS_XCODE_10 | ||
if ([TiUtils isIOSVersionOrGreater:@"12.0"]) { | ||
if ([props objectForKey:@"eligibleForPrediction"]) { | ||
[_userActivity setEligibleForPrediction:[TiUtils boolValue:@"eligibleForPrediction" properties:props]]; | ||
} | ||
|
||
if ([props objectForKey:@"persistentIdentifier"]) { | ||
[_userActivity setPersistentIdentifier:[TiUtils stringValue:@"persistentIdentifier" | ||
properties:props]]; | ||
} | ||
} | ||
#endif | ||
|
||
_userActivity.delegate = self; | ||
} | ||
|
||
|
@@ -425,6 +438,73 @@ - (void)resignCurrent:(id)unused | |
} | ||
[_userActivity resignCurrent]; | ||
} | ||
|
||
#if IS_XCODE_10 | ||
|
||
- (NSNumber *)eligibleForPrediction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make sure all public API's are also in the interface header? It makes it easier to maintain. |
||
{ | ||
if (![TiUtils isIOSVersionLower:@"12.0"]) { | ||
return NUMBOOL(NO); | ||
} | ||
|
||
return NUMBOOL(_userActivity.isEligibleForPrediction); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move all these to native Obj-C 2.0 statements, e.g. |
||
} | ||
|
||
- (void)setEligibleForPrediction:(NSNumber *)value | ||
{ | ||
ENSURE_TYPE(value, NSNumber); | ||
ENSURE_UI_THREAD(setEligibleForSearch, value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The UI-thread should be validated before the type-checks. |
||
if (![TiUtils isIOSVersionLower:@"12.0"]) { | ||
return; | ||
} | ||
[_userActivity setEligibleForPrediction:[TiUtils boolValue:value]]; | ||
} | ||
|
||
- (NSString *)persistentIdentifier | ||
{ | ||
if (![TiUtils isIOSVersionLower:@"12.0"]) { | ||
return nil; | ||
} | ||
|
||
return _userActivity.persistentIdentifier; | ||
} | ||
|
||
- (void)setPersistentIdentifier:(NSString *)value | ||
{ | ||
ENSURE_TYPE(value, NSString); | ||
if ([TiUtils isIOSVersionLower:@"12.0"]) { | ||
return; | ||
} | ||
[_userActivity setPersistentIdentifier:[TiUtils stringValue:value]]; | ||
} | ||
|
||
- (void)deleteSavedUserActivitiesForPersistentIdentifiers:(id)persistentIdentifiers | ||
{ | ||
ENSURE_ARRAY(persistentIdentifiers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you actually test all the new API's so far? Since this is a method, you need to unbox the |
||
if ([TiUtils isIOSVersionLower:@"12.0"]) { | ||
return; | ||
} | ||
[NSUserActivity deleteSavedUserActivitiesWithPersistentIdentifiers:persistentIdentifiers | ||
completionHandler:^{ | ||
if ([self _hasListeners:@"useractivitydeleted"]) { | ||
[self fireEvent:@"useractivitydeleted" withObject:nil]; | ||
} | ||
}]; | ||
} | ||
|
||
- (void)deleteAllSavedUserActivities:(id)unused | ||
{ | ||
if ([TiUtils isIOSVersionLower:@"12.0"]) { | ||
return; | ||
} | ||
[NSUserActivity deleteAllSavedUserActivitiesWithCompletionHandler:^{ | ||
if ([self _hasListeners:@"useractivitydeleted"]) { | ||
[self fireEvent:@"useractivitydeleted" withObject:nil]; | ||
} | ||
}]; | ||
} | ||
|
||
#endif | ||
@end | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.