gpt4 book ai didi

ios - 如何通过我的应用程序在 whatsapp 上邀请用户并分享内容 IOS?

转载 作者:行者123 更新时间:2023-11-29 12:29:56 25 4
gpt4 key购买 nike

我试过这段代码,但它只显示 whatsapp 图标,但不发送内容。请提出我在做什么错

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

self.documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
self.documentationInteractionController.delegate = interactionDelegate;
return self.documentationInteractionController;
}


-(void)btnClick{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; //here i am fetched image path from document directory and convert it in to URL and use bellow


NSURL *imageFileURL =[NSURL fileURLWithPath:getImagePath];
NSLog(@"imag %@",imageFileURL);

self.documentationInteractionController.delegate = self;
self.documentationInteractionController.UTI = @"net.whatsapp.image";
self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self];
[self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

}

最佳答案

在 whatsapp 上发送消息文本:

        NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Test%20message%20whatsapp!"];

if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support Whatsapp!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
}

编辑:和图像:

    if ([[UIApplication sharedApplication] canOpenURL: [NSURL      URLWithString:@"whatsapp://app"]]){

UIImage * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = @"net.whatsapp.image";
_documentInteractionController.delegate = self;

[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];


} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}

看看whatsapp:http://www.whatsapp.com/faq/en/iphone/23559013这个回应:Share image/text through WhatsApp in an iOS app如果你想要有一个与 Whatsapp 集成的 ShareKit:https://github.com/heringb/ShareKit

关于ios - 如何通过我的应用程序在 whatsapp 上邀请用户并分享内容 IOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28023586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com