Skip to content

Commit a3ccae0

Browse files
authored
Merge pull request #2434 from nextcloud/feat/2432/add-support-sharing-pkpasses
feat: Add support for sharing .pkpass files (Apple Wallet)
2 parents 7f9116e + f978fc2 commit a3ccae0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NextcloudTalk/Chat/BaseChatViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import Foundation
77
import NextcloudKit
8+
import PassKit
89
import PhotosUI
910
import UIKit
1011
import Realm
@@ -4129,6 +4130,17 @@ import SwiftUI
41294130
return
41304131
}
41314132

4133+
// Use PKAddPassesViewController for Apple Wallet passes
4134+
if fileExtension == "pkpass" {
4135+
if let passData = try? Data(contentsOf: URL(fileURLWithPath: fileLocalPath)),
4136+
let pass = try? PKPass(data: passData),
4137+
let addPassVC = PKAddPassesViewController(pass: pass) {
4138+
self.present(addPassVC, animated: true)
4139+
self.isPreviewControllerShown = false
4140+
return
4141+
}
4142+
}
4143+
41324144
let preview = QLPreviewController()
41334145
preview.dataSource = self
41344146
preview.delegate = self

NextcloudTalk/Rooms/RoomSharedItemsTableViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import UIKit
77
import QuickLook
8+
import PassKit
89

910
@objcMembers class RoomSharedItemsTableViewController: UITableViewController,
1011
NCChatFileControllerDelegate,
@@ -276,6 +277,7 @@ import QuickLook
276277

277278
let fileExtension = URL(fileURLWithPath: fileLocalPath).pathExtension.lowercased()
278279

280+
// Use VLCKitVideoViewController for file formats unsupported by the native PreviewController
279281
if VLCKitVideoViewController.supportedFileExtensions.contains(fileExtension) {
280282
let vlcViewController = VLCKitVideoViewController(filePath: fileLocalPath)
281283
vlcViewController.delegate = self
@@ -286,6 +288,17 @@ import QuickLook
286288
return
287289
}
288290

291+
// Use PKAddPassesViewController for Apple Wallet passes
292+
if fileExtension == "pkpass" {
293+
if let passData = try? Data(contentsOf: URL(fileURLWithPath: fileLocalPath)),
294+
let pass = try? PKPass(data: passData),
295+
let addPassVC = PKAddPassesViewController(pass: pass) {
296+
self.present(addPassVC, animated: true)
297+
self.isPreviewControllerShown = false
298+
return
299+
}
300+
}
301+
289302
let previewController = QLPreviewController()
290303
previewController.dataSource = self
291304
previewController.delegate = self

ShareExtension/ShareViewController.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,22 @@ - (void)setSharedItemToShareConfirmationViewController:(ShareConfirmationViewCon
375375
}];
376376
return;
377377
}
378+
// Check if shared pkpass (Apple Wallet)
379+
if ([itemProvider hasItemConformingToTypeIdentifier:@"com.apple.pkpass"]) {
380+
[itemProvider loadItemForTypeIdentifier:@"com.apple.pkpass"
381+
options:nil
382+
completionHandler:^(id<NSSecureCoding> _Nullable item, NSError * _Null_unspecified error) {
383+
if ([(NSObject *)item isKindOfClass:[NSData class]]) {
384+
NSLog(@"Shared Pass = %@", item);
385+
NSData *passData = (NSData *)item;
386+
NSString *passFileName = [NSString stringWithFormat:@"Pass_%.f.pkpass", [[NSDate date] timeIntervalSince1970] * 1000];
387+
NSURL *tempURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:passFileName]];
388+
[passData writeToURL:tempURL atomically:YES];
389+
[shareConfirmationVC.shareItemController addItemWithURLAndName:tempURL withName:passFileName];
390+
}
391+
}];
392+
return;
393+
}
378394
// Check if shared URL
379395
if ([itemProvider hasItemConformingToTypeIdentifier:@"public.url"]) {
380396
[itemProvider loadItemForTypeIdentifier:@"public.url"

0 commit comments

Comments
 (0)