webview in iphone - objective-c

I m passing an url as string from UIviewController to another uiviewcontroller..i was able to pass the url successfully but not able to load the string in the webview...in console i m getting a null value in webview could u guys help me out below is the code...
-(void)playAction1
{
webviewcontroller *newEnterNameController = [[webviewcontroller alloc] initWithItem:#"http://www.theappcodeblog.com/?p=222"];
[self.navigationController pushViewController:newEnterNameController animated:YES];
[newEnterNameController release];
}
- (id)initWithItem:(NSString *)url
{
if (self = [super initWithNibName:#"webviewcontroller" bundle:nil])
{
self.title=#"facebook";
self.url1 = [NSURL URLWithString:url];
//URL Requst Object
self.requestObj1 = [NSURLRequest requestWithURL:url1];
NSURLConnection *connection=[[[NSURLConnection alloc] initWithRequest:self.requestObj1 delegate:self]autorelease];
[self.webViewAnnouncements loadRequest:self.requestObj1];
NSLog(#"webView:%#",webViewAnnouncements);
[self.webViewAnnouncements setDelegate:self];
}
return self;
}

While what you're doing doesn't look wrong to me (in truth I'd need to see .h and .xib files) as well to be sure. I would consider the initWithItem to be an unusual pattern.
If I was you, I would init the view controller in the "normal" way using initWithNib and then create the URL as a property type and set it before you present the view controller to the screen.

Related

Open ears text to speech (voice) not working when getting string from another class/controller (IOS, Objective c)

I am very new to objective c and OpenEars so please forgive me if I have some messy code and if I am lost in very simple problem.
Anyhow, I have two controllers in this application. The first being the default ViewController and the second one being a new one that I made called ReplyManagerController.
The code in the ViewController basically uses the one in the tutorial with some (maybe more some) changes.
EDIT:
The app is supposed to be a basic app where a user says something and the app replies.
But the original problem was that I could not get the string to display or TTS to work when my ViewController got it's string from another class/controller.
The answer in my below mentions that it was probably because my other class was calling my ViewController without the self.fliteController initialized.
How would I initialize the ViewController with self.fliteController initialized?
ViewController.m
- (void) pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID {
NSString *strResult = hypothesis; //speech to text to string
ReplyManager* replyObject = [[ReplyManager alloc] init];
[replyObject speechResult:(NSString*)strResult viewController:self];
}
- (void) getReply:(NSString*)replyStr{
[self.fliteController say:replyStr withVoice:self.slt];
[self updateText:replyStr];
}
- (IBAction)updateText:(NSString*)replyStr{
labelOne.text = replyStr;
labelOne.adjustsFontSizeToFitWidth = YES;
labelOne.minimumFontSize = 0;
}
Any help will be great! Thanks!
ReplyManager.m
- (void) speechResult:(NSString*)strResult {
NSString *replystr;
NSString *greetings = #"Hi!";
NSString *sorry = #"Sorry I didn't catch that?";
ViewController* getReply = [[ViewController alloc] init];
if ([strResult isEqualToString:#"HELLO"])
{
replystr = greetings;
[getReply getReply:(NSString*)replystr];
}
else
{
replystr = sorry;
[getReply getReply:(NSString*)replystr];
}
}
EDIT 2:
viewDidLoad Method
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.fliteController = [[OEFliteController alloc] init];
self.slt = [[Slt alloc] init];
self.openEarsEventsObserver = [[OEEventsObserver alloc] init];
[self.openEarsEventsObserver setDelegate:self];
}
ViewController* getReply = [[ViewController alloc] init];
Here you init a new ViewController which does not have self.fliteController defined most likely. You need to reuse previos controller, for example like this:
[replyObject speechResult:(NSString*)strResult viewController:self];
So you can use already initialized viewController later. Overall it is better to initialize objects like viewController or replyController beforehand, not inside callback methods.
It sounds like a timing issue where you're trying to use fliteController before it's been initialized.
In your ViewController class, where do you assign a value to the fliteController property? In an initializer? -(void)viewDidLoad?
In ReplyManagerController add:
ViewController* getReply = [[ViewController alloc] init];
// Add these lines
NSLog(getReply.fliteController); // Is this nil?
[getReply.view layoutIfNeeded];
NSLog(getReply.fliteController); // Is it still nil?
Does the above fix the problem? If so, you're probably initializing fliteController in -(void)viewDidLoad. What's the result of the two NSLog statements?

Objective-C delegate incompatible type

I am using http://www.vfr.org/, pdf viewer, and I try to add a button to open PDF in IBOOK.
I added the button and action to it, but I stuck t the moment when I want open ibooks application with this pdf.
I tried 2 solutions:
button tapped action:
NSURL *fileURL = document.fileURL;
NSString *fileName = document.fileName; // Document
[[UIApplication sharedApplication] openURL:fileURL];
It opens the IBOOKS but the PDF never gets loaded.
I am assuming the URL format can be wrong I tried even hard code a PDF URL like:
NSString *stringURL = #"itms-books://linktopdf.pdf";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
But the same result.
2) Button tapped action:
NSURL *fileURL = document.fileURL;
NSString *fileName = document.fileName; // Document
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
docController.delegate = self;
But I have an warning where I try to delegate: docController.delegate = self;
assigning to id UIDocumentInteractionControllerDelegate from Incompatible ReaderViewController
Can someone help me to make it work at least 1 of these solution.
Has the ReaderViewController this kind of line in the header file: #interface ReaderViewController : NSObject < UIDocumentInteractionControllerDelegate > ?
Your class must conform to the UIDocumentInteractionControllerDelegate protocol, so in your .h file make it look like
#interface ReaderViewController : PerantClass <UIDocumentInteractionControllerDelegate>
{
...
}
Then the compiler will know that your class conforms to that protocol. Of course, you still need to implement the needed methods.
ALso Check this Link - 1 And Link - 2.

Twitter SDK for IPad, weired error on twitter login

when I try to share on twitter I do the following steps
if (!twitterEngine)
{
twitterEngine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
twitterEngine.consumerKey = kOAuthConsumerKey;
twitterEngine.consumerSecret = kOAuthConsumerSecret;
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: twitterEngine delegate: self];
if (controller)
[currentController presentModalViewController: controller animated: YES];
else
[self postTwitterStatus];
}
else {
[self postTwitterStatus];
}
after I got the twitter login view and after I put my pass and user and click add app
I get crash on asembly code, which I don't have an error message, but I saw something weiered also that in the delegates
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(#"Authenicated for %#", username);
[self postTwitterStatus];
}
I got that authintication succeeded but I get that the username == null
how can I solve this issue
Thanks
I did NOT get THIS error, but a similar one using Twitter+OAuth by Ben Gottlieb. If you are using this thing, it is required to use https and not http to connect to twitter.
go to: SA_OAuthTwitterEngine.m and change to:
- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
if (self = (id) [super initWithDelegate: delegate]) {
//CHANGED FROM 'HTTP' TO 'HTTPS':
self.requestTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://twitter.com/oauth/authorize"];
}
return self;
}
give it a try, i'm not sure it's the same as your problem..
Every thing looks fine to me. check with this example and see weather you are getting username in this.

Adding QLPreviewController as subview doesn't load PDF

I'm trying to add a QLPreviewController's view as a subview (no--I cannot use a nav controller or modal). It only shows the fabric background of the QLPreviewController.
I create one and add it as a subview:
QLPreviewController* preview = [[[QLPreviewController alloc] init] autorelease];
preview.dataSource = self;
preview.delegate = self;
preview.view.frame = CGRectMake(0, 0, self.pdfPreviewView.frame.size.width, self.pdfPreviewView.frame.size.height);
self.pdfPreviewView.previewController = preview;
[self.pdfPreviewView addSubview:preview.view];
[preview reloadData];
My QLPreviewControllerDataSource methods work fine (viewing 1 pdf at a time):
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
NSString *path = [[ResourceManager defaultManager] pathForPDF:self.currentPDF];
NSURL *url = [NSURL fileURLWithPath:path];
if ([QLPreviewController canPreviewItem:url]) {
return url; // This always returns
}
return nil; // This line is never executed
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
The data source method always returns the file url, and QLPreviewController says it can open the file, but it never actually does. I just get the background. The self.currentPDF is set before I create the QLPreviewController and does contain the correct information (from CoreData).
The delegate methods never get called. But I'm also not using it in a standard way, so that's not totally unexpected.
I've also tried calling [preview setNeedsLayout], [preview setNeedsDisplay'], and [preview refreshCurrentPreviewItem] but those just call the data source methods and don't change anything.
The PDFs are valid. I can open them in both Xcode and Preview, so that's not the problem. I'm kind of stumped as to why this won't work. Any help would be appreciated in getting this to work.
Turns out I was sending QLPreviewController the wrong path. It wasn't finding the PDF in the bundle correctly. I needed to use pathForResource:ofType:inDirectory.

Objective-C 'RootViewController' may not respond to '-parseXMLFileAtURL:' error in xCode

I have this error when building and running my project in xCode:
RootViewController may not respond to -parseXMLFileAtURL:
I'm attempting to develop the basic Apple RSS Reader from the tutorial at:
http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/
my section of code that this error is occurring in looks like this:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([stories count] == 0)
{
NSString * path = #"http://feeds.feedburner.com/TheAppleBlog";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}
can anybody explain why this parseXMLFileAtURL command gives so much heartache?
Thanks
UPDATED***
I also define parseXMLFileAtURL in the same file; however, I placed that section of the code after the viewDidAppear method (my bad). So when I change the order of the methods that error goes away. But when I do that, I get another error, maybe you guys can help with that error too! here it is:
Class RootViewController does not implement the NSXMLParserDelegate protocol
within this section of code:
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
The error occurs after the line: [rssParser setDelegate:self]; - what might be wrong with that?
In regards to your second question that RootViewController does not conform to the NSXMLParserDelegate protocol. Just add it like this in your RootViewController.h file:
#interface RootViewController : UIViewController <NSXMLParserDelegate> { .....
Silly question: Does your RootViewcontroller class have a method named -parseXMLFileAtURL: defined? If -parseXMLFileAtURL: comes after the method that calls it, you'll also need to declare it in your header.
Make sure you have parseXMLFileAtURL defined in your RootViewController.m
-(void)parseXMLFileAtURL:(NSString *)url
{
...
}
And make sure you have it defined in your header as:
-(void)parseXMLFileAtURL:(NSString *)url;
Also, make sure that when you try to get the contents from the web, you're using an NSURL, not an NSString. You can instantiate a NSURL with a string by:
NSURL *urlFromString = [[NSURL alloc] initWithString:#"http://..."];