8

「ソーシャル」フレームワークを使用して、通常のソーシャル メディア アイコンをすべて表示するモーダル UIActivityViewController を提示するときに、ユーザーがクリックしたアイコンを正確に見つける方法はありますか? つまり、Twitter、Facebook、メール、メッセージなどを選択した場合は?

ドキュメントでこのクラスのデリゲート メソッドがいくつか表示されることを期待していましたが、何も表示されません。

誰かアイデアはありますか?

4

5 に答える 5

4

completionHandler廃止されました。を使用しcompletionWithItemsHandlerます。

activityController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
    NSLog(@"completionWithItemsHandler, activityType: %@, completed: %d, returnedItems: %@, activityError: %@", activityType, completed, returnedItems, activityError);
};
于 2015-11-11T06:48:24.680 に答える
4

この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)")
}
}
于 2016-07-23T09:26:04.960 に答える
2

私の場合、以下のスニペットが機能しました。

[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. 
   }
}];
于 2014-04-29T12:34:30.280 に答える