Unable to Integrate Instagram in iOS App - instagram

i am unable to post my photos on instagram using ios App. I got the following code from a post here on stackoverflow but it does not work. When Instagram starts, it displays error unable to open file. kindly help me.
NSURL *instagramURL = [NSURL URLWithString:#"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"Image.ig"];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:#"Icon.png"]);
[imageData writeToFile:savedImagePath atomically:YES];
NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];
docController = [[UIDocumentInteractionController alloc] init];
docController.delegate = self;
[docController retain];
docController.UTI = #"com.instagram.photo";
[docController setURL:imageUrl];
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}else{
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 show];
[errorToShare release];
}

Minimum resolution for instagram is 612x612. Always JPG.

For the sake of completion, the minimum resolution remains at 612x612 (this is due to displaying images on retina devices), but Instagram now supports both JPEG and PNG images. All non-square images sent to Instagram must be cropped before posting.

Related

Can I use Reader mode (as in Safari) in UIWebView?

I want convert webpage from my app as safari reader mode. Is it real?
you mean this?
#import <SafariServices/SafariServices.h>
NSString *sURL = #"http://google.com";
NSURL *URL = [NSURL URLWithString:sURL];
SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:URL]; // 1.
//SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:URL entersReaderIfAvailable:YES]; // 2.
[self presentViewController:safari animated:YES completion:nil];

GPUImageVideoCamera save video on ios 7

I'm trying to achieve the square video recording like 300*300 so I choose GPUImage but its not working on IOS 7 and giving errors like [UIView nextAvailableTextureIndex]: unrecognized selector sent to instance the error starts when we build the even the sample code
when trying to save the GPUImageVideoCamera
some times its stucks at [movieWriter startRecording]; 
is the GPUImage compatible with ios 7 or we have made some changes ?
here is the code
- (void)viewDidLoad
{
[super viewDidLoad];
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = NO;
filter = [[GPUImageSepiaFilter alloc] init];
initWithRotation:kGPUImageRotateRightFlipVertical];
[videoCamera addTarget:filter];
GPUImageView *filterView = (GPUImageView *)self.view;
[filter addTarget:filterView];
sharing
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
[filter addTarget:movieWriter];
}
- (IBAction)stopRecording:(id)sender {
[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
}
- (IBAction)startRecording:(id)sender {
videoCamera.audioEncodingTarget = movieWriter;
[movieWriter startRecording];
[videoCamera startCameraCapture];
}
My guess is that you modified the .xib or storyboard and didn't set the class of the view that is showing the camera preview to GPUImageView.

UIWebView not able to play sound when hitting it with game url

Both Safari and Chrome on iPhone can play the backend sound when visit this webpage. However, when use UIWebView to visit it, there is no backend sound. There must be some special setting to make it work.
Tried many online solutions, such as, but still not working.Please help me out.
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
_webView.allowsInlineMediaPlayback = YES;
_webView.mediaPlaybackRequiresUserAction = NO;
I have tried this code and it works for me
hope so it will also work for u
-(void)loadWebView:(UIWebView *)webView withUrl:(NSString *)urlString
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback
error:&setCategoryError];
if (!ok) {
NSLog(#"setCategoryError=%#", setCategoryError);
}
webView.allowsInlineMediaPlayback = YES;
webView.mediaPlaybackRequiresUserAction = NO;
NSCharacterSet *characterSet = [NSCharacterSet URLQueryAllowedCharacterSet];
NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:characterSet];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:encodedString]]];
}

Error recording to movie file with AVFoundation

This is a strange problem. I have not changed any code involving this in my project but my video recording has randomly stopped working. When I try to save to a movie to a file I get the following error:
Error Domain=NSOSStatusErrorDomain Code=-12780 "The operation couldn’t be completed. (OSStatus error -12780.)"
I start my capture with the following code:
- (void)initVideoCapture {
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [self frontFacingCameraIfAvailable];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:nil];
[self.captureSession addInput:videoInput];
aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
[self.captureSession addOutput:aMovieFileOutput];
[self detectVideoOrientation:aMovieFileOutput];
[self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];
[self.captureSession startRunning];
}
I then call this method from the viewController to start recording:
- (void) startRecord {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:#"yyyyMMddHHmmss"];
NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
[outputFormatter release];
NSString * fileString = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.mov",newDateString]];
recordFileURL = [[NSURL alloc] initFileURLWithPath:fileString];
[aMovieFileOutput startRecordingToOutputFileURL:recordFileURL recordingDelegate:self];
}
At this time I get the error in this function.
(void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections error:(NSError *)error
What is really weird is that it randomly works sometimes. Like, I will compile the project and it will work 100% of the time. Next time I compile it will work 0%. What could I be doing wrong? Anything obvious?
I've gotten -12780 when the orientation of the device was UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown and UIDeviceOrientationUnknown. Since a recoded video's orientation has to be portrait or landscape, it'll error out on you. I had to write a quick method that checks for those three, and just translates them to portrait.
this seems to be a bug with apple. i solved it by using AVAssetWriter and AVAssetWriterInput

AVAssetWriter startWriting fails on iPod Touch 3rd Gen / OS 4.2.1

My app creates an mp4 file. I've verified that the code I have works on the following devices:
iPad (OS 4.3.2)
iPhone4 (OS 4.2.1)
iPhone 3GS (OS 4.2.1)
.. but the init fails on my iPod Touch 3rd Gen running OS 4.2.1.
This is related to another question on here, but I'm seeing it on a a different iOS device than he was and I've included my init code here. Like the other question, I've tried different pixel formats as well as bitrates, but the AVAssetWriter's status always changes to AVAssetWriterStatusFailed after calling its startWriting function.
Any ideas would be greatly appreciated. I know that mp4 creation is possible on this device because I've downloaded another app that does it just fine on the same device that my code fails on.
Here is the minimal code to do the video setup.
#import "AVFoundation/AVFoundation.h"
#import "AVFoundation/AVAssetWriterInput.h"
#import "AVFoundation/AVAssetReader.h"
#import "Foundation/NSUrl.h"
void VideoSetupTest()
{
int width = 320;
int height = 480;
// Setup the codec settings.
int nBitsPerSecond = 100000;
NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: nBitsPerSecond], AVVideoAverageBitRateKey,
nil];
// Create the AVAssetWriterInput.
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
codecSettings, AVVideoCompressionPropertiesKey,
[NSNumber numberWithInt: width], AVVideoWidthKey,
[NSNumber numberWithInt: height], AVVideoHeightKey,
nil];
AVAssetWriterInput *assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo outputSettings: outputSettings];
[assetWriterInput retain];
// Create the AVAssetWriterPixelBufferAdaptor.
NSDictionary *pixelBufferAdaptorAttribs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,
[NSNumber numberWithInt: width], kCVPixelBufferWidthKey,
[NSNumber numberWithInt: height], kCVPixelBufferHeightKey,
nil];
AVAssetWriterInputPixelBufferAdaptor *pixelBufferAdaptor = [AVAssetWriterInputPixelBufferAdaptor alloc];
[pixelBufferAdaptor initWithAssetWriterInput: assetWriterInput sourcePixelBufferAttributes: pixelBufferAdaptorAttribs];
// Figure out a filename.
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *documentsDirectory = [paths objectAtIndex:0];
char szFilename[256];
sprintf( szFilename, "%s/test.mp4", [documentsDirectory UTF8String] );
unlink( szFilename );
printf( "Filename:\n%s\n\n", szFilename );
// Create the AVAssetWriter.
NSError *pError;
NSURL *url = [NSURL fileURLWithPath: [NSString stringWithUTF8String: szFilename]];
AVAssetWriter *assetWriter = [AVAssetWriter alloc];
[assetWriter initWithURL:url fileType:AVFileTypeMPEG4 error:&pError];
// Bind these things together and start!
assetWriterInput.expectsMediaDataInRealTime = YES;
[assetWriter addInput:assetWriterInput];
//
// ** NOTE: Here's the call where [assetWriter status] starts returning AVAssetWriterStatusFailed
// on an iPod 3rd Gen running iOS 4.2.1.
//
[assetWriter startWriting];
}
I've come to the conclusion that the iPod Touch 3rd Gen just can't create .mp4 videos, period. This would make sense - why include video encoding hardware on a device that doesn't even have a camera to capture videos with?
The thing that was making me think that it could create .mp4 videos was that I had another app that was able to create them from my iPod Touch 3. But upon analyzing that app's .mp4 video, it was actually an H.263 (MPEG-4 part-2) video created with ffmpeg. (Whereas AVFoundation will create H.264 videos if it can do it at all on a device).

Resources