-1
我有图像和视频和文本的表视图,也有共享按钮 想点击共享按钮,然后如何打开社会图标,以及如何分享Instagram的/的WhatsApp/Facebook的/叽叽喳喳媒体 我使用的Xcode 8 IOS 10和目标C 任何机构可以帮我请如何在facebooke上分享图像/ whatsapp/instagram fron ios xcode应用程序
我有图像和视频和文本的表视图,也有共享按钮 想点击共享按钮,然后如何打开社会图标,以及如何分享Instagram的/的WhatsApp/Facebook的/叽叽喳喳媒体 我使用的Xcode 8 IOS 10和目标C 任何机构可以帮我请如何在facebooke上分享图像/ whatsapp/instagram fron ios xcode应用程序
使用此为Facebook和Instagram没有任何集成
selectedIndexCollectionCells是要共享包含图像阵列 其他在Facebook上可以使用多个分享功能(使用Photos Framework)
- (IBAction)shareButtonAction:(id)sender {
if ([selectedIndexCollectionCells count] > 1){
UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"Share!" message:@"Please Select only 1 Image to share" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil];
[alert1 addAction:firstAction];
[self presentViewController:alert1 animated:YES completion:nil];
}
else if ([selectedIndexCollectionCells count] != 0) {
UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"Social Media Platforms" message:@"Where Would you Like to Share" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Instagram" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
[self savePostsPhotoBeforeSharing];
}];
UIAlertAction *secondAction = [UIAlertAction actionWithTitle:@"Facebook" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controllerSLC setInitialText:@""];
[controllerSLC addURL:[NSURL URLWithString:@""]];
[controllerSLC addImage:choosenImage];
[self presentViewController:controllerSLC animated:YES completion:Nil];
}];
UIAlertAction *ThirdAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alert1 addAction:firstAction];
[alert1 addAction:secondAction];
[alert1 addAction:ThirdAction];
[self presentViewController:alert1 animated:YES completion:nil];
}
else {
UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"Share!" message:@"Please Select Image To Share" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil];
[alert1 addAction:firstAction];
[self presentViewController:alert1 animated:YES completion:nil];
}
}
-(void)savePostsPhotoBeforeSharing {
UIImageWriteToSavedPhotosAlbum(choosenImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo: (void *) contextInfo; {
[self sharePostOnInstagram];
}
-(void)sharePostOnInstagram
{
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO],];
__block PHAsset *assetToShare;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
[result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
assetToShare = asset;
}];
if([assetToShare isKindOfClass:[PHAsset class]])
{
NSString *localIdentifier = assetToShare.localIdentifier;
NSString *urlString = [NSString stringWithFormat:@"instagram://library?LocalIdentifier=%@",localIdentifier];
NSURL *instagramURL = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL: instagramURL]) {
[[UIApplication sharedApplication] openURL: instagramURL];
} else {
UIAlertController *removedSuccessFullyAlert = [UIAlertController alertControllerWithTitle:@"Error!!" message:@"No Instagram Application Found!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil];
[removedSuccessFullyAlert addAction:firstAction];
[self presentViewController:removedSuccessFullyAlert animated:YES completion:nil];
}
}
}