Integration of Instagram in iPhone - iphone

I am trying to post a photo to Instagram through my app. I am using UIDocumentInteractionController according to INstagram guidlines
in my .h file
UIDocumentInteractionController *documentInteractionController;
in my .m file
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"IMG_0192" ofType:#"jpg"];
fileToOpen = [fileToOpen substringToIndex:[fileToOpen length] - 3];
fileToOpen=[NSString stringWithFormat:#"%#ig",fileToOpen];
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
NSLog(#"%#",fileToOpen);
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
/*UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#""
message:#"Can open app!"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
*/
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
self.documentInteractionController.UTI = #"com.instagram.photo";
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:#"Its a testing" forKey:#"InstagramCaption"];
is am missing something.??it is not working.

I think your photo ID or file URL is not correct here. I've done this successfully with the following code snippet:
in your .h file:
#property (nonatomic, retain) UIDocumentInteractionController *docDic;
also add the following delegate:
UIDocumentInteractionControllerDelegate
in your .m file:
synthesize the docDic object
Write the following method:
-(UIDocumentInteractionController *)setupControllerWithURL:(NSURL*)fileURL usingDelegate:(id<UIDocumentInteractionControllerDelegate>)interactionDelegate{
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
Then add the following code snippet to your shareToInstagram function:
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"IMG_0192" ofType:#"jpg"];
fileToOpen = [fileToOpen substringToIndex:[fileToOpen length] - 3];
fileToOpen=[NSString stringWithFormat:#"%#.ig",fileToOpen];
NSURL *instagramURL = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", fileToOpen]];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]){
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
self.documentInteractionController.UTI = #"com.instagram.photo";
[self.dic presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
Hopefully it will help you. Best of luck. :-)

Related

Change program from getting music from iTunes to local file using URL

I am currently trying to make an app stream raw data from mic over mulipeer connectivity.
I have been using this tutorial as a base https://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity
Now however I am struggling with changing the URL from itunes library to my local file.
I am no advanced programmer and this is some kind of summer project.
When the program is getting music from itunes library it uses this code:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
[self dismissViewControllerAnimated:YES completion:nil];
if (self.outputStreamer) return;
self.song = mediaItemCollection.items[0];
NSMutableDictionary *info = [NSMutableDictionary dictionary];
info[#"title"] = [self.song valueForProperty:MPMediaItemPropertyTitle] ? [self.song valueForProperty:MPMediaItemPropertyTitle] : #"";
info[#"artist"] = [self.song valueForProperty:MPMediaItemPropertyArtist] ? [self.song valueForProperty:MPMediaItemPropertyArtist] : #"";
MPMediaItemArtwork *artwork = [self.song valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [artwork imageWithSize:self.albumImage.frame.size];
if (image)
info[#"artwork"] = image;
if (info[#"artwork"])
self.albumImage.image = info[#"artwork"];
else
self.albumImage.image = nil;
self.songTitle.text = info[#"title"];
self.songArtist.text = info[#"artist"];
[self.session sendData:[NSKeyedArchiver archivedDataWithRootObject:[info copy]]];
NSArray *peers = [self.session connectedPeers];
if (peers.count) {
self.outputStreamer = [[TDAudioOutputStreamer alloc] initWithOutputStream:[self.session outputStreamForPeer:peers[0]]];
[self.outputStreamer streamAudioFromURL:[self.song valueForProperty:MPMediaItemPropertyAssetURL]];
[self.outputStreamer start];
But I want it to get music from the recorder:
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
#"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:nil];
I have been struggling with this for a while now and would appreciate any kind of help!

Attaching a mp3 file to email directly from app?

I am working on an app where, if the user selects a sound, they can email it to themselves from the app.
The attachment part 'appears' to work, however, when I send the email, the recipient has no attachment?
On the iPad/iPhone itself, it looks like it is attaching it when it comes to compose, but it is not working? :/
Here is the code I am using;
- (void)onSend:(id)sender{
int nIndex;
UIButton *btnSender = (UIButton *)sender;
NSLog( #"%d", btnSender.tag );
for ( int i = 0; i < [ m_aryFileName count ]; i++ ) {
if( i == ( btnSender.tag - 100 ) ){
nIndex = i;
}
}
NSString *strFileName = [ m_aryFileName objectAtIndex:nIndex ];
strFileName = [ strFileName stringByAppendingString:#".mp3" ];
NSData* nData = [ NSData dataWithContentsOfFile:strFileName ];
MFMailComposeViewController *pickerMail = [[MFMailComposeViewController alloc] init];
pickerMail.mailComposeDelegate = self;
[pickerMail setSubject:#"myMail Attachment"];
// Attach an image to the email
[pickerMail addAttachmentData:nData mimeType:#"audio/mp3" fileName:strFileName ];
// Fill out the email body text
NSString *emailBody = #"Here is your attachment";
[pickerMail setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:pickerMail animated:YES];
[pickerMail release];
}
try this code mate,
NSString *strFileName = [m_aryFileName objectAtIndex:nIndex];
strFileName = [strFileName stringByAppendingString:#".mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:strFileName];
NSData *nData = [[NSData alloc] initWithContentsOfURL:fileURL];
MFMailComposeViewController *pickerMail = [[MFMailComposeViewController alloc] init];
pickerMail.mailComposeDelegate = self;
[pickerMail setSubject:#"myMail Attachment"];
[pickerMail addAttachmentData:nData mimeType:#"audio/mpeg" fileName:strFileName ];
NSString *emailBody = #"Here is your attachment";
[pickerMail setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:pickerMail animated:YES];
Below code might be useful to you:
NSData *videoData = [NSData dataWithContentsOfURL:mediaUrl];
[mailcomposer addAttachmentData:videoData mimeType:#"video/mp4" fileName:#"Video"]
Try using a mime type of audio/mpeg instead. You can get this value by running the following code:
#import <MobileCoreServices/MobileCoreServices.h>
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
(__bridge CFStringRef)#"mp3",
NULL);
CFStringRef mimeTags = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
CFRelease(uti);
NSString *mediaType = [NSString stringWithString:(__bridge NSString *)mimeTags];
CFRelease(mimeTags);
How does that work?
if ([MFMailComposeViewController canSendMail] && m_pDataArray != nil)
{
NSString * pSongPath = [[NSBundle mainBundle] pathForResource:#"song" ofType"#"mp3"]; ;//get the file
MFMailComposeViewController * pMailComposer = [[MFMailComposeViewController alloc] init];
pMailComposer.mailComposeDelegate = self;
[pMailComposer setMessageBody:#"msg body" isHTML:NO];
NSURL * pFileUrl = [[[NSURL alloc] initFileURLWithPath:pSongPath] autorelease];
NSData * pData = [[[NSData alloc] initWithContentsOfURL:pFileUrl] autorelease];
[pMailComposer addAttachmentData:pData mimeType:#"audio/mpeg" fileName:#"song.mp3" ]];
[self presentModalViewController:pMailComposer animated:YES];
[pMailComposer release];
}
else
{
UIAlertView *pAlert = [[UIAlertView alloc] initWithTitle:#"Failure" message:#"Your device doesn't support the composer sheet" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[pAlert show];
[pAlert release];
pAlert = nil;
}
be sure that the file should have valid extension like .mp3 , in that case it will work properly

Open saved PDF file in documents folder of iPad in iBooks?

I have saved a pdf file in the apps documents folder on the iPad. I want the user to open that PDF file on iPad using iBooks. Is there any way to open the PDF in iBooks which is saved in documents folder of the application?
EDIT : Best option : Use UIActivityViewController
//create file path here
NSString *strFileURL = [NSTemporaryDirectory() stringByAppendingPathComponent:#"data.pdf"];
//Check if file path exists or not
BOOL checkExist = [[NSFileManager defaultManager] fileExistsAtPath:strFileURL isDirectory:nil];
if (checkExist)
{
//create NSURL object from string path
NSURL *urlFilePath = [NSURL fileURLWithPath:strFileURL];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[urlFilePath] applicationActivities:nil];
//for iOS8 check
if ( [activityViewController respondsToSelector:#selector(popoverPresentationController)] )
{
//use triggering UI element like say here its button
activityViewController.popoverPresentationController.sourceView = yourBtnSender;
}
//now present activityViewController
[self presentViewController:activityViewController animated:YES completion:NULL];
}
Another option use UIDocumentInteractionController for this:
//create file path here
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *pdfFilePath [documentsDir stringByAppendingPathComponent:yourPdfFile.pdf];// your yourPdfFile file here
NSURL *url = [NSURL fileURLWithPath:pdfPath];
//create documentInteractionController here
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];
//set delegate
docController.delegate = self;
//provide button's frame from where popover will be lauched
BOOL isValid = [docController presentOpenInMenuFromRect:yourReadPdfButton.frame inView:self.view animated:YES]; // Provide where u want to read pdf from yourReadPdfButton
//check if its ready show popover
if (!isValid)
{
NSString * messageString = [NSString stringWithFormat:#"No PDF reader was found on your device. In order to consult the %#, please download a PDF reader (eg. iBooks).", yourPDFFileTitle];
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:messageString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
Use UIDocumentInteractionControllerDelegate method
// UIDocumentInteractionController delegate method
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
NSLog(#"dissmissed");
}
Credit goes to #Mutix 's answer

Making a call programmatically from iPhone app and returning back to the app after ending the call

I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.

Trouble loading html file from plist to webView on iPhone

trouble loading html file from plist to webView using following code in
FAQDetailViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *WebPath = [Path stringByAppendingPathComponent:WebFile];
UIWebView *tempWeb = [[UIWebView alloc] initWithContentsOfFile:WebPath];
[webView loadData:tempWeb]; //I think my issue is here. I am not understanding how to implement the the code here
[tempWeb release];
}
loaded here with this peace of code in FAQViewController.m:
FAQDetailViewController *faqdvController = [[FAQDetailViewController alloc] initWithNibName:#"FAQDetailView" bundle:[NSBundle mainBundle]];
faqdvController.WebFile = [dictionary objectForKey:#"faqDesc"]; //html file from plist file placed here
faqdvController.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:faqdvController animated:YES];
[faqdvController release];
You can try it this way:
NSString *bundle = [[NSBundle mainBundle] bundlePath];
NSString *webPath = [bundle stringByAppendingPathComponent:{htmlFilename}]
UIWebView* browser = [[UIWebView alloc] initWithFrame:
CGRectMake(0, 0, 200, 300)];
[browser loadRequest:[NSURLRequest requestWithURL:
[NSURL fileURLWithPath:webPath]]];
[self addSubview:browser];
You'll also want to set delegates on the browser so you get informed when the contents have finished loading.