My UIDocumentsInteractionController is working as far as presenting an action sheet with a button that says "iBooks" but when I click on that button, it just dismisses and it doesn't take me to iBooks. Here's my code:
NSString *filenamePath =[NSString stringWithFormat:#"temp.%#", [[file path] pathExtension]];
NSString *docDir = [DataCenter getDocumentsDirectoryPath];
NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];
NSURL *url = [NSURL fileURLWithPath:fullPath];
UIDocumentInteractionController *c = [UIDocumentInteractionController interactionControllerWithURL:url];
BOOL success = [c presentOpenInMenuFromBarButtonItem:buttonBack animated:YES];
What am I doing wrong?
Thanks
For those stuck at this: You don't need to set yourself up as UIDocumentInteractionController's delegate at all.
Problem was [UIDocumentInteractionController interactionControllerWithURL:url] is being autoreleased. It thought it would be retained internally by the action sheet being shown but apparently it's not.
So yea, gotta retain it until action sheet dismisses.
Try checking the UIDocumentInteractionControllerDelegate methods documentInteractionController:willBeginSendingToApplication: and documentInteractionController:didEndSendingToApplication:. If your view controller is the delegate of the document interaction controller, that should clue you in to where the problem may be.
Also, you should validate that the file you're trying to use elsewhere (a PDF I assume) is actually a what you expect it to be.
Related
How to display the created file name and contents on textview? This is my code. Iam able to display the file name and its contents in NSLog but not on textview though i have given the outlet for textview. Please help me with this issue.
-(IBAction) open: (id) sender
{
// Create instance of UITextView
textView = [UITextView alloc];
initWithFrame:[[UIScreen mainScreen] applicationFrame]];
NSString *homeDir = NSHomeDirectory();
// Add text
textView.text= homeDir;
NSLog(#"%#", homeDir);
textfield.text= #"output will go here..";
NSString *myFilePath = [[NSBundle mainBundle]
pathForResource:#"Myfile"
ofType:#"txt"];
NSString *myFileContents = [NSString stringWithContentsOfFile:myFilePath
encoding:NSUTF8StringEncoding
error:nil];
NSString *s = [NSString stringWithFormat:#"myFilePath: %#, Contents of file:%#",myFilePath, myFileContents];
NSLog(#"%#", s);
textView.text= s;
}
Does the textView work at all? Have you tried:
textView.text = #"TestText"? If the textView remains empty you need to check the outlet/ check whether the textView is added to the ViewController properly. I think this should solve your problem.
There is an issue with your text view setup.
If an outlet is connected to the text view, you do not need to create it in code (which you are doing).
If you create it in code, you have to add it as a subview to the desired view (which you are not doing).
I think you forgot to add the textview in your parentview; I assume you are creating runtime textview. Just add this line in your code.
[self.view addSubview:textView];
I am working on iPhone App similar to Pimp My text available here:
http://itunes.apple.com/us/app/pimp-my-text-send-color-text/id489972714?mt=8
I am trying to find a way for sending Colored and animated Messages as the app does.
I have tried this by using UIWebview but it seems the paste board is used in the app to send the iMessage but its not working. The paste board copies the message from editor screen of message and paste it to default iMessage controller. But I am not sure how it is done in the app.
Can anyone suggest any way to send the Colored, animated text with effects?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
May be the question I asked did not clarified correctly as what I want. But the above was something that solved my purpose.
I want to be able to refresh a view from another class, but nothing I have tried is working. My application is a tabbed application with several tabs set up. I have a method called refresh in my ViewController1 class that looks like this
-(void)TestMe{
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"widgjson" ofType:#"json"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
NSString *responseString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: #"json.txt"];
[responseString writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
[self loadView];
[self viewDidLoad];
}
This works fine. When the application first loads up, it loads a different json, then when I click this button it loads a new JSON and then updates the view. This is just temporary to test out refreshing. However if I try to call this method from another class, or from the AppDelegates ApplicationDidEnterForeground methods, nothing happens. I tried calling it like this
-(void)TestMe{
ViewController1 *vc = [[ViewController1 alloc] init];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"widgjson" ofType:#"json"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
NSString *responseString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: #"json.txt"];
[responseString writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
[vc loadView];
[vc viewDidLoad];
}
So why does this method not work from any other classes. All I want to is to be able to refresh a view from another class or when the application loads up, but just can't seem to find anything that works.
Would be very grateful if someone could point me in right direction!
EDIT: UPDATING TO CLARIFY
Okay, what I have done for the time being which I don't like is put this
exit(0);
Inside AppDelegates ApplicationDidEnterBackground. This works to an extent, but is not an ideal solution.
What I would like to have happen is that when application is opened again, the AppDelegate gets run again which sets up the tabs. The JSON pulled from the server can affect the order of the tabs which is why I need the AppDelegates ApplicationDidFinishLaunching method to reload itself again.
Also I would like to know can I do this from another class in the application. The first time my application is loaded it asks for the users phone number, which is sent to the server which then generates an PIN. After this is done, then I want the AppDelegate method to load up and begin setting up the tabs and the order etc.
To prevent your application running in the background (and so to force reloading when you exit and re-enter) you can set the UIApplicationExitsOnSuspend key to YES in your info.plist.
However, this is probably a bit drastic.
Your current code for refreshing from the application delegate is a non-starter because you are creating a new instance of the view controller rather than talking to one that is on the screen.
For this reason it is best not to involve your application delegate at all in the process.
Instead, your view controller can register itself as an observer for the UIApplicationDidBecomeActive notification, and do whatever it needs to itself. You would typically register for this notification on viewDidLoad, and unregister on viewDidUnload (since, by definition, if you have unloaded the view, you don't need to refresh it when the app comes back up!).
You would register as follows (using blocks here as they are the future):
Declare an ivar of type id to hold the observer object, let's call it becomeActiveObserver in this case. So, wherever you are declaring your ivars, add id becomeActiveObserver. Then, in viewDidLoad:
becomeActiveObserver = [[NSNotificationCenter defaultCenter]
addObserverForName:UIApplicationDidBecomeActive
object:nil
queue: nil
usingBlock:^(NSNotification *note){
//put your reloading code in here
[self TestMe];
}];
And remove like so in viewDidUnload:
[[NSNotificationCenter defaultCenter] removeObserver:becomeActiveObserver;
You can follow a similar pattern to pick up notifications (your own, or system ones) from anywhere else in your app. This is a better design than passing everything through the app delegate as it involves much looser coupling.
I guess clickMe is an action to a button.if you want to refresh the viewcontroller at startup then add a function in viewcontroller similar to clickme or any function that refreshes the view and call it from applicationWillEnterForeground method or you may try this :-
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"app will enter foreground");
[viewController clickMe:NULL];
}
and you may change the file in the applicationWillEnterForeground method of appDelegate if your application requires.
When I bring up a "New Message" manually I will see a camera icon to the left of the text edit area. When I use the MFMessageComposeViewController it will not display this icon which means you cannot insert images. I know this can be done because the guys that made txtAgif can do it. One subtle difference is the Caps is turned on. This might be a clue as to how they are getting this to work.
I know that MFMessageComposeViewController does not allow you to insert images programmatically and that is why I'm doing the copy to UIPasteboard trick. This part works perfectly.
This same question has been asked here and here the question has not been answered except for the "It can't be done."
This is my first post so I did not have a high enough ranking to contribute to the other question posts.
How are they doing this? Is there a trick to MFMessageComposeViewController or are they using something completely different?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
I found the answer! Using UIApplication sharedApplication to launch a blank message works while MFMessageComposeViewController does not. Because I'm using the UIPasteboard I do not need to insert items into the body.
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
This is a bug in MFMessageComposeViewController because why would they allow images to be inserted into one and not the other. I would insert an image but I'm not allowed to because I do not have enough reputation.
I am new to iPhone developemnt.
NSString myUrl = #"www.google.com";
I need to know how to create a hyperlink for the above NSString variable.
In the MFMailComposeViewController I need to use like below
[mailViewController setMessageBody:myUrl isHTML:YES];
Please help me out.
Thanks for any help.
The easiest way is to make the UILabel into a UIButton, style it (use Custom type to get rid of button look). Then connect to an Action that opens safari.
The action should do this:
NSURL *url = [[[ NSURL alloc ] initWithString: #"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];