Skip to content

Commit

Permalink
Add INSendMessageIntent NSUserActivity support to the main App
Browse files Browse the repository at this point in the history
This allows for Shorcut and with merge of matrix-org/matrix-ios-kit#906 support for Siri suggestions to open the app.

Signed-off-by: Finn Behrens <[email protected]>
  • Loading branch information
kloenk committed Sep 17, 2021
1 parent 8510027 commit f6a19ec
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 0 deletions.
1 change: 1 addition & 0 deletions Riot/Generated/InfoPlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal enum InfoPlist {
internal static let nsMicrophoneUsageDescription: String = _document["NSMicrophoneUsageDescription"]
internal static let nsPhotoLibraryUsageDescription: String = _document["NSPhotoLibraryUsageDescription"]
internal static let nsSiriUsageDescription: String = _document["NSSiriUsageDescription"]
internal static let nsUserActivityTypes: [String] = _document["NSUserActivityTypes"]
internal static let uiBackgroundModes: [String] = _document["UIBackgroundModes"]
internal static let uiLaunchStoryboardName: String = _document["UILaunchStoryboardName"]
internal static let uiRequiredDeviceCapabilities: [String] = _document["UIRequiredDeviceCapabilities"]
Expand Down
20 changes: 20 additions & 0 deletions Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,26 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct
{
continueUserActivity = [self handleUniversalLink:userActivity];
}
else if ([userActivity.activityType isEqualToString:INSendMessageIntentIdentifier])
{
INInteraction *interaction = userActivity.interaction;
if (interaction && [interaction.intent isKindOfClass:[INSendMessageIntent class]])
{
INSendMessageIntent *intent = (INSendMessageIntent *)(interaction.intent);
INPerson *person = intent.recipients.firstObject;
if (person && person.customIdentifier) {
NSString *identifier = person.customIdentifier;

[self startDirectChatWithUserId:identifier completion:NULL];
// TODO: initialize text if from a siri shortcut
continueUserActivity = YES;
} else {
MXLogWarning(@"A recipient was missing in the INSendMessageIntent");
}
} else {
MXLogWarning(@"How can an INSendMessageIntent activity not have an INSendMessageIntent?");
}
}
else if ([userActivity.activityType isEqualToString:INStartAudioCallIntentIdentifier] ||
[userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier])
{
Expand Down
6 changes: 6 additions & 0 deletions Riot/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<string>The photo library is used to send photos and videos.</string>
<key>NSSiriUsageDescription</key>
<string>Siri is used to perform calls even from the lock screen.</string>
<key>NSUserActivityTypes</key>
<array>
<string>INSendMessageIntent</string>
<string>INStartAudioCallIntent</string>
<string>INStartVideoCallIntent</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand Down
Loading

0 comments on commit f6a19ec

Please sign in to comment.