2012-11-19 64 views
0

我在iPad上UIActivityViewController

這裏與UIActivityViewController一個問題是我的代碼:

NSString* someText = @"Hi, I am using the official iEveryThing Tech app #iEveryTech"; 
     NSString* Website = [NSURL URLWithString:@"https://itunes.apple.com/us/app/ieverytech/id578148847?l=de&ls=1&mt=8"]; 
     NSArray* dataToShare = @[someText,Website]; 

     Class activityViewController = NSClassFromString(@"UIActivityViewController"); 

     if(activityViewController) { 
      UIActivityViewController* activityViewController = 
     [[UIActivityViewController alloc] initWithActivityItems:dataToShare 
              applicationActivities:nil]; 
      [self presentViewController:activityViewController animated:YES completion:nil];} 



     } 

iPhone上的郵件作曲家這裏發送郵件,但不是作曲家對iPad後視圖會消失是我的作曲家:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 

    if (error) { 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" 

                 message:[NSString stringWithFormat:@"error %@", [error description]] 

                 delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil]; 

     [alert show]; 


     [self dismissModalViewControllerAnimated:YES]; 

    } 

    else { 

     [self dismissModalViewControllerAnimated:YES]; 

    } 

} 

回答

0

首先,當使用activityViewController時,你的類不是郵件編輯器的代理,代碼也不會被調用。這一切都是在activityViewController內部處理的。

至於你的觀點不被解僱,實施activityViewController的完整塊調用。在塊中一定要關閉視圖控制器。

1

的activityViewController用於發送郵件的本地方法不需要使用mailComposeController,這樣

NSMutableArray *items = [NSMutableArray new]; 
    [items addObject:@"text for share"]; 
    [items addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:self.imagePath]]]; 

NSArray *activityItems = [NSArray arrayWithArray:items]; 

self.activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:whatsapp,instagram, nil]]; 

self.activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint,UIActivityTypeAirDrop,UIActivityTypeCopyToPasteboard]; 

[self presentViewController:self.activityVC animated:YES completion:nil];