UIActivityViewController completion handler still calls action if user presses cancel
That's what the completed
argument is for:
[controller setCompletionHandler:^(NSString *activityType, BOOL completed) {
if (!completed) return;
CWStatusBarNotification *notification = [CWStatusBarNotification new];
[notification displayNotificationWithMessage:@"✓ Successfully Shared Centre!"
forDuration:3.0f];
notification.notificationLabelBackgroundColor = [UIColor colorWithRed:38.0f/255.0f green:81.0f/255.0f blue:123.0f/255.0f alpha:1.0f];
notification.notificationLabelTextColor = [UIColor whiteColor];
}];
IOS swift how to know when activityViewController has been successfully used
You can add a completion handler to your UIActivityViewController
. In the completion handler, check whether the user submitted using the completed
value. You'll probably want to do something like this:
func sharedShareAction(controller: UIViewController, sender: UIButton) {
controller.present(activityViewController,animated: true, completion: nil)
activityViewController.completionWithItemsHandler = { activity, completed, items, error in
if !completed {
// handle task not completed
return
}
IncreaseShareByOne()
}
}
Check the API docs for more info.
UIActivityViewController completion handler is !completed when using AirDrop
I've found something of interest for you but unfortunately I couldn't test it as AirDrop didn't want to function between my iDevices. Sorry about that.
Anyway, you could try setCompletionWithItemsHandler
checking for activityType
:
[activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"completed: %@, \n%d, \n%@, \n%@,", activityType, completed, returnedItems, activityError);
}];
If activityType
is of type com.apple.airdrop.etc
(just a guess) then the user has tapped on the icon. Hope it can help.
Is there any way to check message sent successfully from UIActivityViewController swift?
Unfortunately what you are asking is not possible.
The activity indicator will only tell you the following:
- What option the user selected
- Did the user complete the sharing operation (eg. Did he actually send a message)
You will not be able to know if the message was edited before being sent. The most you can do is check if the user at least selected the Message option and not, for example, the Copy option.
Related Topics
iOS - Using Storyboard and Autolayout to Center the Uiscrollview
How to Properly Add Child View Controller in iOS 8 with Swift
Parse Starter Project Login and Register View Controllers Errors
Document or Cache Path Changes on Every Launch in iOS 8
How to Make a Grouped Barchart with iOS-Charts
Open Viewcontroller from Tab Like in Instagram Camera Page on iOS
How to Detect When User Used Password Autofill on a Uitextfield
Autolayout Ignores Multi-Line Detailtextlabel When Calculating Uitableviewcell Height (All Styles)
Statusbar Overlapping Content in iOS7
String Replace Phone Number iOS Swift
Bypass Code Signing with Xcode 6
Phimageresultisdegradedkey/Phimagefileurlkey Is Not Found
Property 'Self.*' Not Initialized at Super.Init Call
Pass Uicollectionview Touch Event to Its Parent Uitableviewcell
Change Pin Image on Mkmapview in Swift
Uploading Image with iOS App to Server File Size Is Too Large