2015-08-10 66 views
8

Tôi có mã dưới đây để chia sẻ bài viết trên Instagram.Instagram InstagramGiới thiệu không hoạt động

-(void) shareInstagram { 
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; 
    if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not 
    { 
     UIImage *instaImage = mImg.image; 
     NSData *imageData = UIImagePNGRepresentation(instaImage); //convert image into .png format. 
     NSLog(@"imageData.leeee===%d", imageData.length); 
     if (imageData.length<=100) { 
      [self.view makeToast:localize(@"instaErr2") duration:2.0 position:@"bottom"]; 
     } else { 
      NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager 
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it 
      NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory 
      NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //add our image to the path 
      [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image) 
      NSLog(@"image saved"); 

      CGRect rect = CGRectMake(0 ,0 , 0, 0); 
      UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); 
      [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
      UIGraphicsEndImageContext(); 
      NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"]; 
      NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave]; 
      NSLog(@"jpg path %@",jpgPath); 
      NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath]; 
      NSLog(@"with File path %@",newJpgPath); 
      NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath]; 
      NSLog(@"url Path %@",igImageHookFile); 

      self.documentController.UTI = @"com.instagram.exclusivegram"; 
      self.documentController = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
      self.documentController=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 

      NSString *globalString; 

      if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"PoPinFrom"] isEqualToString:@"user"]) { 
       globalString = [NSString stringWithFormat:@"%@ @ %@\n\nhttp://egkw.com/ArticleDetail.aspx?id=%@\n\niPhone : %@\n\nAndroid : %@", [[productDetailsArray objectAtIndex:0] valueForKey:@"Title"], localize(@"appName"), [[productDetailsArray objectAtIndex:0] valueForKey:@"Id"], localize(@"appStoreLink"), localize(@"playStoreLink")]; 
      } else { 
       globalString = [NSString stringWithFormat:@"%@ @ %@\n\nhttp://egkw.com/ArticleDetail.aspx?id=%@\n\niPhone : %@\n\nAndroid : %@", [[productDetailsArray objectAtIndex:0] valueForKey:@"Title"], localize(@"appName"), [[productDetailsArray objectAtIndex:0] valueForKey:@"Id"], localize(@"appStoreLink"), localize(@"playStoreLink")]; 
      } 

      globalString = [NSString stringWithFormat:@"%@\n\n#EGKW", globalString]; 
      NSLog(@"insta==globalString==%@", globalString); 
      self.documentController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:globalString, @"InstagramCaption", nil]; 
      // self.documentController.annotation = [NSDictionary dictionaryWithObject:globalString forKey:@"InstagramCaption"]; 
      [self.documentController presentOpenInMenuFromRect:rect inView: self.view animated:YES]; 
     } 
    } 
    else 
    { 
     NSLog (@"Instagram not found"); 
     DTAlertView *myAl = [DTAlertView alertViewWithTitle:localize(@"err001") message:localize(@"instaErr") delegate:nil cancelButtonTitle:localize(@"dismiss") positiveButtonTitle:nil]; 
     [myAl setDismissAnimationWhenButtonClicked:DTAlertViewAnimationSlideTop]; 
     [myAl showWithAnimation:DTAlertViewAnimationSlideBottom]; 
    } 
} 

Mã này đã hoạt động tốt hơn trước đó. Tuy nhiên khi tôi nhận thấy, tôi thấy rằng chú thích không hiển thị trên Instagram. Sau khi nghiên cứu tôi đã thay đổi

self.documentController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:globalString, @"InstagramCaption", nil]; 

để

self.documentController.annotation = [NSDictionary dictionaryWithObject:globalString forKey:@"InstagramCaption"]; 

Nhưng nó vẫn không làm việc.

Bất kỳ ý tưởng nào đang xảy ra sự cố?

Instagram có thay đổi bất kỳ chính sách nào như Facebook không?

+0

Tôi đang chạy vào cùng một vấn đề chính xác, trong trường hợp của tôi, tôi đang cố gắng một hashtag, nhưng vô ích. –

+0

@ CanPoyrazoğlu: Tôi nghĩ Instagram đã thay đổi chính sách của mình như Facebook nhưng Instagram chưa đăng. Vì vậy, không chắc liệu đây là lỗi hay thay đổi chính sách ... –

+0

Chỉ cần thấy điều đó. Rất tiếc khi thấy điều này trong khi triển khai chức năng chính xác này. –

Trả lời

16

Instagram hiện đã loại bỏ việc điền vào trường chú thích bằng bộ điều khiển tương tác.

Xem bài đăng blog từ họ

Instagram developer blog

+0

* kênh chia sẻ thường cảm thấy spam *, *** là điều lạ lùng từ Instagram *** –

+4

Có bất kỳ truy đòi nào không? Tôi có một ứng dụng phụ thuộc nhiều vào phụ đề đang được gửi. Ứng dụng đó bây giờ hoàn toàn vô giá trị ... Vì vậy, tôi hy vọng có một cách khác. – zillaofthegods

Các vấn đề liên quan