2017-04-04 72 views

回答

0

試試這個代碼

-(void)shareContent{ 

NSString * message = @"My too cool Son"; 

UIImage * image = [UIImage imageNamed:@"boyOnBeach"]; 

NSArray * shareItems = @[message, image]; 

UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil]; 

[self presentViewController:avc animated:YES completion:nil]; 

} 
+0

上面的代碼共享任何活動類型相同的內容,但假設如果我想分享打印選項不同的圖像,然後該怎麼辦 –

+0

@MinkleGarg如果你想分享多個圖像,如果你不是創造array.or的圖像想要共享動態圖像而不是設置ImageView控件名稱。 – iOS

+0

假設activityviewcontroller出現,現在用戶想分享打印活動的圖像,但這個圖像應該與其他活動共享圖像不同。因此,如果用戶點擊打印選項,並且用戶選擇(臉譜,微博等),我們可以保留不同的圖像,那麼圖像應該是不同的。是否有任何方法在選擇活動類型時使用不同的內容。 –

0

可以在.m文件做到這一點使用UIActivityItemProvider

在.h文件中

@interface APActivityProvider : UIActivityItemProvider <UIActivityItemSource> 

@end 

@implementation APActivityProvider 

- (id) activityViewController:(UIActivityViewController *)activityViewController 
      itemForActivityType:(NSString *)activityType { 
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]) 
     return @"This is a facebook post!"; 
    if ([activityType isEqualToString:UIActivityTypeMessage]) 
     return @"SMS message text"; 
    if ([activityType isEqualToString:UIActivityTypeMail]) 
     return @"Email text here!"; 

} 

- (void) shareAppData { 
    APActivityProvider *ActivityProvider = [[APActivityProvider alloc] initWithPlaceholderItem: @「」]; 
    NSArray *Items = @[ActivityProvider]; 


    UIActivityViewController *ActivityView = [[UIActivityViewController alloc] 
               initWithActivityItems:Items 
               applicationActivities:nil]; 

    [ActivityView setValue:@「Title for email」 forKey:@"subject"]; 

    [self presentViewController:ActivityView animated:YES completion:nil]; 

    [ActivityView setCompletionHandler:^(NSString *act, BOOL done) 
    { 
     NSString *ServiceMsg = nil; 
     if ([act isEqualToString:UIActivityTypeMail]) 
      ServiceMsg = @"Mail sended!"; 
     if ([act isEqualToString:UIActivityTypePostToTwitter]) 
     ServiceMsg = @"Post on twitter, ok!"; 
     if ([act isEqualToString:UIActivityTypePostToFacebook]) 
     ServiceMsg = @"Post on facebook, ok!"; 
     if ([act isEqualToString:UIActivityTypeMessage])   
     ServiceMsg = @"SMS sended!"; 

     if (done) 
     { 
      UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
      [Alert show]; 
     } 
    }]; 
} 
相關問題