-
-
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 6 commits
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 |
---|---|---|
|
@@ -16,6 +16,74 @@ | |
- (id)initWithOptions:(NSDictionary *)props; | ||
@property (nonatomic, strong) NSUserActivity *userActivity; | ||
|
||
- (id)isSupported:(id)unused; | ||
|
||
- (NSString *)activityType; | ||
|
||
- (void)setActivityType:(id)value; | ||
|
||
- (NSString *)title; | ||
|
||
- (void)setTitle:(id)value; | ||
|
||
- (NSDictionary *)userInfo; | ||
|
||
- (void)setUserInfo:(id)info; | ||
|
||
- (NSString *)webpageURL; | ||
|
||
- (void)setWebpageURL:(id)value; | ||
|
||
- (NSNumber *)needsSave; | ||
|
||
- (void)setNeedsSave:(id)value; | ||
|
||
- (void)becomeCurrent:(id)unused; | ||
|
||
- (void)invalidate:(id)unused; | ||
|
||
- (void)addContentAttributeSet:(id)contentAttributeSet; | ||
|
||
- (NSNumber *)eligibleForPublicIndexing; | ||
|
||
- (void)setEligibleForPublicIndexing:(id)value; | ||
|
||
- (NSNumber *)eligibleForSearch; | ||
|
||
- (void)setEligibleForSearch:(id)value; | ||
|
||
- (NSNumber *)eligibleForHandoff; | ||
|
||
- (void)setEligibleForHandoff:(id)value; | ||
|
||
- (NSString *)expirationDate; | ||
|
||
- (void)setExpirationDate:(id)UTCDateFormat; | ||
|
||
- (NSArray *)requiredUserInfoKeys; | ||
|
||
- (void)setRequiredUserInfoKeys:(id)keys; | ||
|
||
- (NSArray *)keywords; | ||
|
||
- (void)setKeywords:(id)keys; | ||
|
||
- (void)resignCurrent:(id)unused; | ||
|
||
#if IS_XCODE_10 | ||
- (NSString *)persistentIdentifier; | ||
|
||
- (void)setPersistentIdentifier:(NSString *)value; | ||
|
||
- (NSNumber *)eligibleForPrediction; | ||
|
||
- (void)setEligibleForPrediction:(NSNumber *)value; | ||
|
||
- (void)deleteSavedUserActivitiesForPersistentIdentifiers:(id)persistentIdentifiers; | ||
|
||
- (void)deleteAllSavedUserActivities:(id)unused; | ||
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. Not only the new methods but all methods ;-). Including code-docs and params-descriptions. 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. All method exposing is fine. Do we use code-docs and params-description in header file in Titanium SDK? 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 Ti core-developers, it will help knowing which params are used in the "boxed" arguments. But it looks fine for now. |
||
#endif | ||
|
||
@end | ||
|
||
#endif | ||
#endif |
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,77 @@ - (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 @(_userActivity.isEligibleForPrediction); | ||
} | ||
|
||
- (void)setEligibleForPrediction:(NSNumber *)value | ||
{ | ||
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. |
||
ENSURE_TYPE(value, NSNumber); | ||
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_SINGLE_ARG(persistentIdentifiers, NSArray); | ||
|
||
for (id object in persistentIdentifiers) { | ||
ENSURE_TYPE(object, NSString); | ||
} | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2017-Present by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
/* eslint-env mocha */ | ||
/* global Ti */ | ||
/* eslint no-unused-expressions: "off" */ | ||
'use strict'; | ||
var should = require('./utilities/assertions'); | ||
|
||
describe.ios('Titanium.App.iOS.UserActivity', function () { | ||
|
||
var userActivity; | ||
|
||
before(function () { | ||
userActivity = Ti.App.iOS.createUserActivity({ | ||
activityType: 'com.setdirection.home', | ||
title: 'activity 1', | ||
userInfo: { | ||
msg: 'hello world' | ||
}, | ||
eligibleForSearch: true, | ||
eligibleForPrediction: true, | ||
persistentIdentifier: 'titanium_activity_identifier' | ||
}); | ||
}); | ||
|
||
after(function () { | ||
userActivity = null; | ||
}); | ||
|
||
it('constructor', function () { | ||
should(userActivity).be.an.Object; | ||
should(userActivity).have.readOnlyProperty('apiName').which.is.a.String; | ||
should(userActivity.apiName).be.eql('Ti.App.iOS.UserActivity'); | ||
}); | ||
|
||
it('#deleteSavedUserActivitiesForPersistentIdentifiers()', function () { | ||
should(userActivity.deleteSavedUserActivitiesForPersistentIdentifiers).be.a.Function; | ||
}); | ||
|
||
it('#deleteAllSavedUserActivities()', function () { | ||
should(userActivity.deleteAllSavedUserActivities).be.a.Function; | ||
}); | ||
|
||
}); |
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.
For more information, see [the Apple docs](https://developer.apple.com/documentation/sirikit/donating_shortcuts?language=objc).