2013-10-30 3 views
54

iOS 7をサポートするほとんどのiOSアプリケーションでこの共有形式の形式(画像は下に表示されています)を見ました。 この共有オプションを実装するための既定のコード/下の画像に?あなたがUIActivityViewControllerで探しているものをiOS 7の既定の共有

+0

このチュートリアルをチェックしてください:http://www.appcoda.com/ios7-airdrop-programming-tutorial/ – Sakiboy

答えて

4

にあなたのリンクを与える以上のことを行うことができない一般的な質問をしているので、あなたが投稿画像内のコントローラは

1

UIActivityViewControllerクラスのドキュメントをUIActivitiyViewController this is a linkは何かということですあなたは探している。

あなたがアイテムまたはアプリケーションのいずれかを指定することができます

UIActivityViewController *actCont = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; 
15

、サンプルコード

- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url 
    { 
     NSMutableArray *sharingItems = [NSMutableArray new]; 
     if (text) { 
      [sharingItems addObject:text]; 
     } 
     if (image) { 
      [sharingItems addObject:image]; 
     } 
     if (url) { 
      [sharingItems addObject:url]; 
     } 
     UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; 
     [self presentViewController:activityController animated:YES completion:nil]; 
    } 

コールshareTextの小片、あなたがnilで共有したくないものを残します。

[self shareText:@"Hello world" andImage:nil andUrl:nil]; 
1

デフォルト共有のために次のコードを使用してください。お客様の要件に応じて、shareItemsアレイにさらに多くのアイテムを追加することができます。

NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects: 
           @"Hello", 
           [UIImage imageNamed:@"your_image.png"], 
           @"http://google.com/", nil]; 
[self shareItemToOtherApp:shareItems]; 

方法に従い、他のアプリにデフォルトの共有テキストやイメージのためである: -

-(void)shareItemToOtherApp:(NSMutableArray *)shareItems{ 
    UIActivityViewController *shareController = [[UIActivityViewController alloc] 
               initWithActivityItems: shareItems applicationActivities :nil]; 

    [shareController setValue:@"Sharing" forKey:@"subject"]; 
    shareController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll]; 

    shareController.completionHandler = ^(NSString *activityType, BOOL completed) 
    { 
     //NSLog(@" activityType: %@", activityType); 
     //NSLog(@" completed: %i", completed); 
    }; 

    [self presentViewController: shareController animated: YES completion: nil]; 
} 

あなたはカスタム共有シートを作成したい場合は、次のコードを使用します。このためには、<Social/Social.h>フレームワークをインポートする必要があります。

-(void)shareOnFacebook:(id)sender { 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
    { 
     SLComposeViewController *faceSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
     // NSLog(@"%@", messageField.text);//This returns the appropriate string 
     [faceSheet setInitialText:@"Hellooooooo"]; 
     //The facebook VC appears, but initial text is not set to messageField.text 
     [self presentViewController:faceSheet animated:YES completion:nil]; 
    } 
    else 
    { 
     NSLog(@"Please first install Application and login in Facebook"); 
    } 
} 

-(void)shareOnTwitter:(id)sender { 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
    { 
     SLComposeViewController *tweetSheet = [SLComposeViewController 
               composeViewControllerForServiceType:SLServiceTypeTwitter]; 
     [tweetSheet setInitialText:@"Hello"]; 
     [self presentViewController:tweetSheet animated:YES completion:nil]; 
    } 
    else{ 
     NSLog(@"Please first install Application and login in Twitter"); 
    } 
} 

ご希望のものです。どんな心配も私に戻ってくる。 :)

関連する問題