2015-09-15 48 views
1

在我的應用程序中想要打開UIActivityViewController中的自定義彈出窗口。所以我不想在Facebook上打開默認共享彈出。那麼如何解決這個彈出窗口或如何阻止在iOS中彈出該彈出窗口。 請給我的解決方案...如何阻止在iOS中的UIActivityViewController中打開默認的Facebook共享?

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopup) name:dismissMJPopUp object: nil]; 

     //ReferFriendVC *okpopup=[[ReferFriendVC alloc]initWithNibName:@"ReferFriendVC" bundle:nil]; 
     // [self presentPopupViewController:okpopup animationType:MJPopupViewAnimationSlideBottomTop]; 

     UIPopoverController *popup; 
     MyActivityItemProvider *message = [[MyActivityItemProvider alloc] init]; 
     NSArray *activityItems; 
     UIImage *myImage=[UIImage imageNamed:@"3.png"]; 
     activityItems = @[message, myImage]; 


     NSArray * applicationActivities = nil; 

     UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities]; 

     activityViewController.excludedActivityTypes = @[ 
                  UIActivityTypePostToWeibo, 
                  UIActivityTypeAssignToContact, 
                  UIActivityTypeAirDrop, 
                  UIActivityTypeAddToReadingList, 
                  UIActivityTypeCopyToPasteboard, 
                  UIActivityTypeSaveToCameraRoll, 
                  UIActivityTypePrint, 
                  UIActivityTypePostToFlickr,UIActivityTypePostToTencentWeibo               // Whatever you want to exclude 
                  ]; 

     if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){ 

      activityViewController.popoverPresentationController.sourceView = 
      self.view; 
     } 
     if(isiPhone) 
     { 
      [self presentViewController:activityViewController animated:YES completion:nil]; 

     } 
     else{ 
      popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController]; 
      [popup presentPopoverFromRect:CGRectMake(0, screenheight, 768, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
     } 
     [activityViewController setCompletionWithItemsHandler:^(NSString *act, BOOL completed, NSArray *returnedItems, NSError *activityError) 
      { 

       NSLog(@"act type %@",act); 
       NSString *ServiceMsg = nil; 
       if ([act isEqualToString:UIActivityTypeMail]) 
        ServiceMsg = @"Mail sent"; 
       NSLog(@"mail sent"); 
       if ([act isEqualToString:UIActivityTypeAssignToContact]) 
        ServiceMsg = @"Post on twitter, ok!"; 

       if ([act isEqualToString:UIActivityTypePostToFacebook]) 
        ServiceMsg = @"Post on facebook, ok!"; 
       [popup dismissPopoverAnimated:YES]; 

      }]; 

而且在myActivityItemProvide.h

#import "MyActivityItemProvider.h" 


@implementation MyActivityItemProvider 


- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType 
{ 
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]) { 
     NSLog(@"mail method called "); 
// 
     if([AppDelegate NetworkRechability]) 
     { 
      //  FrindListVC *leavefeed=[[FrindListVC alloc]initWithNibName:@"FrindListVC" bundle:nil]; 
      //  [self.navigationController pushViewController:leavefeed animated:YES]; 

      FBSDKAppInviteContent *content1 =[[FBSDKAppInviteContent alloc] init]; 
      content1.appLinkURL = [NSURL URLWithString:@"https://fb.me/4931252562362626805"]; 
      //optionally set previewImageURL 
      content1.appInvitePreviewImageURL = [NSURL URLWithString:@"http://files.parsdrterfsdfetfss.com/79580e8563-55656cc-456455f2-a20f-7f69e783b14d/tfss-f9e2626e-dfsdfsfsdfsdf519c-4ca3-ae47-015ffeaad0f7-fbinvite-01.png"]; 

      // present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate` 
      [FBSDKAppInviteDialog showWithContent:content1 
             delegate:self]; 

      // [[[self parentViewController] parentViewController] presentViewController:activityViewController animated:YES completion:nil]; 
//   activityViewController.view.hidden=YES; 


     } 
     else 
     { 

      UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Internet Not Available" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [errorAlert show]; 
      [SVProgressHUD dismiss]; 

     } 

    } 


    return @"No provider"; 
} 
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error 
{ 
    NSLog(@"error %@",error); 
} 
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)result 
{ 
    // NSLog(@"result %@",result); 
} 
- (id) activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { return @""; } 
@end 
+0

秀你試過的代碼 –

回答

0

可以排除或塊用下面的代碼UIActivityViewController打開默認的Facebook共享:

activityViewController.excludedActivityTypes = [UIActivityTypePostToFacebook] 
相關問題