How Can I share image +text caption(URL) on whatsapp from iphone?

前端 未结 2 1052
无人共我
无人共我 2021-02-13 09:17

I have used following code for share image on WhatsApp but I am unable to set the caption text using following code.

I have tried annotation property of UIDocument

2条回答
  •  無奈伤痛
    2021-02-13 09:57

    NSError *error       = nil;
    NSURL   *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:&error];
    
    UIImage *image     = [UIImage imageNamed:@"share.png"];
    NSURL   *tempFile  = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"];
    NSData  *imageData = UIImageJPEGRepresentation(image, 1.0);
    
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    NSLog(@"%@",docDir);
    NSLog(@"saving png");
    
    NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
    NSData *data1 = [NSData dataWithData:UIImageJPEGRepresentation(image,1.0)];
    [data1 writeToFile:pngFilePath atomically:YES];
    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
    _documentInteractionController.delegate = self;
    _documentInteractionController.UTI = @"net.whatsapp.image";
    
    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
    

提交回复
热议问题