2013-04-03 154 views
1

我的客戶想要在Instagram上分享圖片。我在instagram上實現了共享圖像,但我無法用特殊的標籤分享它。這是我的代碼到目前爲止。如何從Instagram獲取具有特殊標籤的圖片?

- (IBAction)sharePhotoOnInstagram:(id)sender { 

    UIImagePickerController *imgpicker=[[UIImagePickerController alloc] init]; 
    imgpicker.delegate=self; 
    [self storeimage]; 
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; 
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) 
    { 

     CGRect rect = CGRectMake(0 ,0 , 612, 612); 
     NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/15717.ig"]; 

     NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]]; 
     dic.UTI = @"com.instagram.photo"; 
     dic.delegate = self; 
     dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
     dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
     dic.delegate = self; 
     [dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 
     // [[UIApplication sharedApplication] openURL:instagramURL]; 
    } 
    else 
    { 
     // NSLog(@"instagramImageShare"); 
     UIAlertView *errorToShare = [[UIAlertView alloc] initWithTitle:@"Instagram unavailable " message:@"You need to install Instagram in your device in order to share this image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

     errorToShare.tag=3010; 
     [errorToShare show]; 
    } 
} 


- (void) storeimage 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"15717.ig"]; 
    UIImage *NewImg = [self resizedImage:picTaken :CGRectMake(0, 0, 612, 612) ]; 
    NSData *imageData = UIImagePNGRepresentation(NewImg); 
    [imageData writeToFile:savedImagePath atomically:NO]; 
} 

-(UIImage*) resizedImage:(UIImage *)inImage: (CGRect) thumbRect 
{ 
    CGImageRef imageRef = [inImage CGImage]; 
    CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef); 

    // There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate 
    // see Supported Pixel Formats in the Quartz 2D Programming Guide 
    // Creating a Bitmap Graphics Context section 
    // only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst, 
    // and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported 
    // The images on input here are likely to be png or jpeg files 
    if (alphaInfo == kCGImageAlphaNone) 
     alphaInfo = kCGImageAlphaNoneSkipLast; 

    // Build a bitmap context that's the size of the thumbRect 
    CGContextRef bitmap = CGBitmapContextCreate(
               NULL, 
               thumbRect.size.width,  // width 
               thumbRect.size.height,  // height 
               CGImageGetBitsPerComponent(imageRef), // really needs to always be 8 
               4 * thumbRect.size.width, // rowbytes 
               CGImageGetColorSpace(imageRef), 
               alphaInfo 
               ); 

    // Draw into the context, this scales the image 
    CGContextDrawImage(bitmap, thumbRect, imageRef); 

    // Get an image from the context and a UIImage 
    CGImageRef ref = CGBitmapContextCreateImage(bitmap); 
    UIImage* result = [UIImage imageWithCGImage:ref]; 

    CGContextRelease(bitmap); // ok if NULL 
    CGImageRelease(ref); 

    return result; 
} 

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate 
{ 
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; 
    interactionController.delegate = self; 

    return interactionController; 
} 

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller 
{ 

} 

- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action 
{ 
    // NSLog(@"5dsklfjkljas"); 
    return YES; 
} 

- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller performAction:(SEL)action 
{ 
    // NSLog(@"dsfa"); 
    return YES; 
} 

- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application 
{ 
    // NSLog(@"fsafasd;"); 
} 

注意:這工作正常。

我已按照他們的文檔http://instagram.com/developer/iphone-hooks/但無法從它得到更好的主意!現在不知道下一步如何使用哈希標籤和其他信息共享圖像。

其次我想檢索與特定主題標籤共享到應用程序中的所有圖像。

請指導我!提前致謝!

回答

0

首先,從iPhone Hooks,在「文件交流」:

包括與您的照片預填充標題,您可以設置文件交互請求到一個NSDictionary包含下一個NSString註釋屬性關鍵「InstagramCaption」。注意:此功能將在Instagram 2.1及更高版本上提供。

你需要添加類似:

dic.annotation = [NSDictionary dictionaryWithObject:@"#yourTagHere" forKey:@"InstagramCaption"]; 

其次,你需要看看Tag Endpoints,如果你想拉下來的圖像與特定的標籤。

+0

謝謝你凱爾! Thankx很多。我們可以檢索不同用戶使用相同標籤共享的多張圖片嗎? – happycoder

+0

是的,看看/ tags/tag-name/media /最近的端點。 – kyleobrien

相關問題