Skip to content
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

Merged
merged 7 commits into from
Aug 28, 2018
59 changes: 59 additions & 0 deletions apidoc/Titanium/App/iOS/UserActivity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`true`

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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: |
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
80 changes: 80 additions & 0 deletions iphone/Classes/TiAppiOSUserActivityProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -425,6 +438,73 @@ - (void)resignCurrent:(id)unused
}
[_userActivity resignCurrent];
}

#if IS_XCODE_10

- (NSNumber *)eligibleForPrediction
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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. @(_userActivity.isEligibleForPrediction) and @(NO). But that should be done with an own PR and an own ticket. Maybe we can deprecate the old macros in SDK 8.0.0?.

}

- (void)setEligibleForPrediction:(NSNumber *)value
{
ENSURE_TYPE(value, NSNumber);
ENSURE_UI_THREAD(setEligibleForSearch, value);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 persistentIdentifiers attribute with ENSURE_SINGLE_ARG(persistentIdentifiers, NSArray).

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