2017-09-27 863 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); 
     } 
    }; 
}