2017-09-27 871 views
1
共享时,请选择不同的项目

首次应用程序安装和共享图像不工作,它显示警告:此项目不能共享。在WhatsApp的

此产品不能共享。请选择其他项目。

我会尝试第二次图像共享成功。什么是问题?

-(void)TwitterAndmanyMore 
{ 
    UIImage * image = _imageView.image; 
    NSArray * items = @[image]; 
    UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil]; 

    // and present it 
    [self presentActivityController:controller]; 
} 
- (void)presentActivityController:(UIActivityViewController *)controller { 

    // for iPad: make the presentation a Popover 
    controller.modalPresentationStyle = UIModalPresentationPopover; 
    [self presentViewController:controller animated:YES completion:nil]; 

    UIPopoverPresentationController *popController = [controller popoverPresentationController]; 
    popController.permittedArrowDirections = UIPopoverArrowDirectionAny; 
    popController.barButtonItem = self.navigationItem.leftBarButtonItem; 

    // access the completion handler 
    controller.completionWithItemsHandler = ^(NSString *activityType, 
               BOOL completed, 
               NSArray *returnedItems, 
               NSError *error) 
    { 
     // react to the completion 
     NSLog(@"----retu------%@",returnedItems); 
     if (completed) 
     { 

      [self showContine]; 
      //[self viewWillAppear:YES]; 
      // user shared an item 
      NSLog(@"We used activity type%@", activityType); 
     } else { 
      // user cancelled 
      NSLog(@"We didn't want to share anything after all."); 
     } 

     if (error) { 
      NSLog(@"An Error occured: %@, %@", error.localizedDescription, error.localizedFailureReason); 
     } 
    }; 
} 
+0

这个问题只发生在iOS的11或旧版本吗? –

+0

直到我检查ios 11先生 –

+0

检查它在ios 10或ios 9中,因为我也只在ios 11中遇到与UIActivityViewController有关的问题。如果你确认问题只在ios 11上,那么编辑你的问题,因为它只发生在ios 11中。 –

回答

0

使用下面这个问题的代码它的工作

-(void)TwitterAndmanyMore 
{ 
// UIImage * image = _imageView.image; 
// NSLog(@"Image Data %@",image); 
// NSArray * items = @[@"", image]; 

    tempImage = [UIImage imageNamed:@"Sample.jpg"]; 
    tempImage = _imageView.image; 
    NSString *theMessage = @""; 
    NSArray *items; 

    CGImageRef cgref = [tempImage CGImage]; 
    CIImage *cim = [tempImage CIImage]; 



    if (cim != nil || cgref != NULL) 
    { 
     items = @[theMessage,tempImage]; 
    } 
    else 
    { 
     items = @[theMessage]; 
    } 
    NSLog(@"Image Data %@",items); 
    // build an activity view controller 
    UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil]; 

    // and present it 
    [self presentActivityController:controller]; 
} 
- (void)presentActivityController:(UIActivityViewController *)controller { 

    // for iPad: make the presentation a Popover 
    controller.modalPresentationStyle = UIModalPresentationPopover; 
    [self presentViewController:controller animated:YES completion:nil]; 

    UIPopoverPresentationController *popController = [controller popoverPresentationController]; 
    popController.permittedArrowDirections = UIPopoverArrowDirectionAny; 
    popController.barButtonItem = self.navigationItem.leftBarButtonItem; 

    // access the completion handler 
    controller.completionWithItemsHandler = ^(NSString *activityType, 
               BOOL completed, 
               NSArray *returnedItems, 
               NSError *error) 
    { 
     // react to the completion 
     NSLog(@"----retu------%@",returnedItems); 
     if (completed) 
     { 

      [self showContine]; 
      //[self viewWillAppear:YES]; 
      // user shared an item 
      NSLog(@"We used activity type%@", activityType); 
     } else { 
      // user cancelled 
      NSLog(@"We didn't want to share anything after all."); 
     } 

     if (error) { 
      NSLog(@"An Error occured: %@, %@", error.localizedDescription, error.localizedFailureReason); 
     } 
    }; 
}