2017-07-19 62 views
0

我正在使用swift 3在線賣家的應用程序。然後這些應用程序可以將這些項目分享到社交媒體中。但我有一個分享給Instagram的問題。每個應用都有自己的url方案來打開它的權利?你們可以幫我嗎,Instagram的網址計劃是什麼,可以直接在Instagram上打開剪裁頁面?如何將圖片從我的應用程序分享到Instagram

+0

我的目標C做只是調用這個函數沒有整合如果你想我可以分享該代碼 –

+0

我很高興,如果你可以與我分享... –

+0

@NurAinMdIsa,請查看附加的URL - https://stackoverflow.com/questions/36406515/post-uiimage-to- Instagram的 - 使用 - 迅速相似到slcomposeviewcontroller –

回答

1

我已經使用照片框架的OBJ下,在資產獲得的圖像

-(void)savePostsPhotoBeforeSharing { 
     UIImageWriteToSavedPhotosAlbum(choosenImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); //Choosen image is image that you need to send on Instagram 
    } 


    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo: (void *) contextInfo; { 
     [self sharePostOnInstagram]; // this function save image .io format and check if any error exist or not 
    } 


    -(void)sharePostOnInstagram. //this will share your selected image on Instagram through its installed app 
    { 
     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]; 
    } 
} 
} 

當你想分享圖片到Instagram的

[self savePostsPhotoBeforeSharing]; 
相關問題