「ソーシャル」フレームワークを使用して、通常のソーシャル メディア アイコンをすべて表示するモーダル UIActivityViewController を提示するときに、ユーザーがクリックしたアイコンを正確に見つける方法はありますか? つまり、Twitter、Facebook、メール、メッセージなどを選択した場合は?
ドキュメントでこのクラスのデリゲート メソッドがいくつか表示されることを期待していましたが、何も表示されません。
誰かアイデアはありますか?
「ソーシャル」フレームワークを使用して、通常のソーシャル メディア アイコンをすべて表示するモーダル UIActivityViewController を提示するときに、ユーザーがクリックしたアイコンを正確に見つける方法はありますか? つまり、Twitter、Facebook、メール、メッセージなどを選択した場合は?
ドキュメントでこのクラスのデリゲート メソッドがいくつか表示されることを期待していましたが、何も表示されません。
誰かアイデアはありますか?
completionHandler
廃止されました。を使用しcompletionWithItemsHandler
ます。
activityController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"completionWithItemsHandler, activityType: %@, completed: %d, returnedItems: %@, activityError: %@", activityType, completed, returnedItems, activityError);
};
このSOの回答に基づく: https://stackoverflow.com/a/34581940/2177085
これには、WhatsApp または Gmail を介してユーザーが共有されていることを確認することも含まれます。activityType を出力して、他のタイプを追加できます。
let activityViewController = UIActivityViewController(activityItems: [finalMsg as NSString], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
activityViewController.completionWithItemsHandler = {(activityType, completed:Bool, returnedItems:[AnyObject]?, error: NSError?) in
// Return if cancelled
if (!completed) {
print("user clicked cancel")
return
}
if activityType == UIActivityTypeMail {
print("share throgh mail")
}
else if activityType == UIActivityTypeMessage {
print("share trhought Message IOS")
}
else if activityType == UIActivityTypePostToTwitter {
print("posted to twitter")
}
else if activityType == UIActivityTypePostToFacebook {
print("posted to facebook")
}
else if activityType == UIActivityTypeCopyToPasteboard {
print("copied to clipboard")
}
else if activityType! == "net.whatsapp.WhatsApp.ShareExtension" {
print("activity type is whatsapp")
}
else if activityType! == "com.google.Gmail.ShareExtension" {
print("activity type is Gmail")
}
else {
// You can add this activity type after getting the value from console for other apps.
print("activity type is: \(activityType)")
}
}
私の場合、以下のスニペットが機能しました。
[activityController setCompletionHandler:^(NSString *act, BOOL done)
{
NSLog(@"act type %@",act);
NSString *ServiceMsg = nil;
if ( [act isEqualToString:UIActivityTypeMail] )
ServiceMsg = @"Mail sent";
if ( [act isEqualToString:UIActivityTypePostToTwitter] )
ServiceMsg = @"Post on twitter, ok!";
if ( [act isEqualToString:UIActivityTypePostToFacebook] )
ServiceMsg = @"Post on facebook, ok!";
if ( done )
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[Alert show];
[Alert release];
}
else
{
// didn't succeed.
}
}];