當用戶在 UIActivityViewController(右上角)中按下“x”以取消共享時,我在 Swift 中找不到如何執行操作的完整代碼。
這是我目前擁有的:
do {
try pdfData.write(to: temporaryFileURL)
let vc = UIActivityViewController(activityItems: [temporaryFileURL], applicationActivities: [])
self.present(vc, animated: true, completion: nil)
} catch {
print(error)
}
我發現這個可能有效的 Objective-C 代碼。有人可以幫我把它轉換成 Swift 并告訴我如何用我目前擁有的東西來實作它嗎?
vc.completionWithItemsHandler = ^(NSString *activityType,
BOOL completed,
NSArray *returnedItems,
NSError *error){
// react to the completion
if (completed) {
// user shared an item
NSLog(@"We used activity type%@", activityType);
} else {
// user cancelled
NSLog(@"We didn't want to share anything after all.");
}
if (error) {
NSLog(@"An Error occured: %@, %@", error.localizedDescription, error.localizedFailureReason);
}
};
謝謝!
uj5u.com熱心網友回復:
你可以這樣做。
vc.completionWithItemsHandler = { activityType, completed, returnedItems,
error in
// Your logic here
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/453807.html
