problem loading url in view - objective-c

i'm confused about an error while i'm trying an url in a view. while compiling i get the following 2 errors (in h-file an in m-file):
Expected identifier before '*' token
maybe anybody can help me out of my trouble? thanks in advance!
my code:
File "RssWebViewController.h":
#import "RssWebViewController.h"
- (void)NavigateToUrl:(NSString) *url{
NSURL *requestUrl = [NSURL URLWithString:self.url];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj]
}
File "RssWebViewController.h":
#import <UIKit/UIKit.h>
#interface RssWebViewController : UIView {
UIWebView *WebView;
}
#property (nonatomic, retain) IBOutlet UIWebView *WebView;
- (void) NavigateToUrl:(NSString) *url;
#end

You need to structure your function definition with the * inside the parentheses:
- (void) NavigateToUrl: (NSString *) url;
It seems that you're referencing self.url, but really should be looking at url (no self.)
Here's a clearer version of the method:
- (void) NavigateToUrl: (NSString *) url {
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: url]];
[self.WebView loadRequest: request];
}

Related

Locating an audio file to play in Objective C

I'm a Swift guy going back to do some Objc work and I'm trying to add a sound to my app, problem is, the path is null when trying to locate the file
The file is located at myProj/Resources/Sounds/genericButtonPress.wav
NSString *path = [[NSBundle mainBundle] pathForResource:#"myProj/Resources/Sounds/genericButtonPress" ofType:#"wav"];
NSLog(#"%#", path); // NULL
NSURL *url = [NSURL fileURLWithPath:path];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:NULL];
[player play];
From the docs, it looked like pathForResource had to be absolute but I've also tried with just genericButtonPress as my string.
Would love some help here. Thanks!
The answer is this:
Remember kids, always make sure that your files are assigned to your proper target or things won't show up and won't work. That goes for fonts and audio files especially.
My solution is
ViewController.h
#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
#interface ViewController : UIViewController
#property (nonatomic,strong)AVAudioPlayer *player;
- (IBAction)actionPlayAudio:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize player;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)actionPlayAudio:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"youraudiofilename" ofType:#"wav"];
NSURL *soundFileURL = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
[player play];
}

SocketRocket and pinning certificate error?

I'm working with SocketRocket, so far everything has been working fine and today I wanted to try to pin down a (self signed) certificate but I get an error:
- (void)connectWebSocket {
webSocket.delegate = nil;
webSocket = nil;
NSString *urlString = [NSString stringWithFormat: #"wss://%#:%#", server_ip, server_port];
//NSLog(#"%#", urlString);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]
cachePolicy: NSURLRequestUseProtocolCachePolicy
timeoutInterval:5.0];
// pin down certificate
NSString *cerPath = [[NSBundle mainBundle] pathForResource:#"myOwnCertificate" ofType:#"cer"];
NSData *certData = [[NSData alloc] initWithContentsOfFile:cerPath];
CFDataRef certDataRef = (__bridge CFDataRef)certData;
SecCertificateRef certRef = SecCertificateCreateWithData(NULL, certDataRef);
id certificate = (__bridge id)certRef;
[request setSR_SSLPinnedCertificates:#[certificate]];
SRWebSocket *newWebSocket = [[SRWebSocket alloc] initWithURLRequest: request];
newWebSocket.delegate = self;
[newWebSocket open];
socketIsOpen = true;
}
Error: No visible #interface for 'NSURLRequest' declares the selector 'setSR_SSLPinnedCertificates:'
Am I missing something?
Thanks!
You need #import "SRWebSocket.h".
SR_SSLPinnedCertificates is a property on the NSURLRequest (CertificateAdditions) category in https://github.com/square/SocketRocket/blob/master/SocketRocket/SRWebSocket.h
The request needs to be a NSMutableURLRequest type. When your request is a NSURLRequest type, the SR_SSLPinnedCertificates is readonly, so you can NOT set it.
#pragma mark - NSURLRequest (CertificateAdditions)
#interface NSURLRequest (CertificateAdditions)
#property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates;
#end
#pragma mark - NSMutableURLRequest (CertificateAdditions)
#interface NSMutableURLRequest (CertificateAdditions)
#property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates;
#end
Change your code to this:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]
cachePolicy: NSURLRequestUseProtocolCachePolicy
timeoutInterval:5.0];
This should works :)

Facebook iOS SDK: how to get user's Facebook status?

I am getting very hardtime using the Facebook iOS SDK reference because I am not an expert coder. I just have this simple question.
I know the following code brings me the user information...
[facebook requestWithGraphPath:#"me" andDelegate:self];
but where does it go? How can I, let's say, get the User's First Name or status and set it up as the value of a label?
I would be thankful gazillion times if someone writes me the whole code in answer.
When you call this method, here's what the SDK expects:
self implements FBRequestDelegate
self has a method request:didLoad
Here's a quick code sample:
---- MyClass.h BEGIN ----
#import <UIKit/UIKit.h>
#import "FBConnect.h"
#interface MyClass : NSObject <FBSessionDelegate, FBRequestDelegate>
#property (nonatomic, retain) Facebook *facebook;
#property (nonatomic, retain) NSString *userStatus;
#end
---- MyClass.h END ----
---- MyClass.m BEGIN ----
#import "MyClass.h"
#implementation MyClass
#synthesize facebook;
#synthesize userStatus;
- (id)init {
self = [super init];
if (self) {
facebook = [[Facebook alloc] initWithAppId:#"App ID Here" andDelegate:self];
}
return self;
}
- (void)fbDidLogin {
NSLog(#"Facebook logged in!");
[facebook requestWithGraphPath:#"me" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSLog(#"Request loaded! Result: %#", result);
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *jsonResponse = [parser objectWithString:result error:nil];
userStatus = [jsonResponse objectForKey:message];
[parser release];
NSLog(#"User's status message: %#", userStatus);
}
#end
---- MyClass.m END ----
Hope this helps!
Umair,
After getting the access token you can use this code:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://graph.facebook.com/me?access_token=youracesstoken"]];
NSError *err = nil;
NSURLResponse *resp = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&err];
if (resp != nil) {
NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(#"stringResponse---%#",stringResponse);
// stringResponse will be in JSON Format you need to use a JSON parser (Like SBJSON or TouchJSON)
}

How can I load an HTML file?

How do I load an HTML file into my app (xcode)? I'm using the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
}
When I start the app, I only see a white page. What's wrong?
.h file:
#import <UIKit/UIKit.h>
#interface poules : UIViewController {
IBOutlet UIWebView *webView;
}
#property (nonatomic,retain) UIWebView *webView;
#end
Here is a working example from one of my projects. My index.html file is in a folder called Documentation/html in the resources directory. Its important to note that these are "folder references", not groups (hence the blue icon):
then to load it in a webView:
NSString *resourceDir = [[NSBundle mainBundle] resourcePath];
NSArray *pathComponents = [NSArray arrayWithObjects:resourceDir, #"Documentation", #"html", #"index.html", nil];
NSURL *indexUrl = [NSURL fileURLWithPathComponents:pathComponents];
NSURLRequest *req = [NSURLRequest requestWithURL:indexUrl];
[webView loadRequest:req];
try loadHTMLString:baseURL: method
NSString *html=[NSString stringWithContentsOfFile:your_html_path encoding:NSUTF8StringEncoding error:nil];
[webview loadHTMLString:html baseURL:baseURL];
First thing you can check whether your webView is connected or not.
If it is then, you can break down your code to check what is wrong with request that you are trying to load.
1.. Create a NSString for the file path like this, and check if the path is returned or not.
NSString *urlString = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
2.. Create a NSURL from the above string like this, and check if the url is correct or nil.
NSURL *url = [NSURL URLFromString:urlString];
3.. And then create the request.
NSURLRequest *request = [NSURLRequest requestFromURL:url];

Xcode is not calling asp.net webservice

I have oracle database and using webservice i want to insert some records in to it
So i created webservice in asp.net as follows
public bool PickPill(string Me_id, string Mem_device_id, string Test_datetime, string Creation_id, string PillBayNo)
{
string Hed_seq_id = Hed_seq_Id();
bool ResultHED = InsHealthEData(Hed_seq_id, Mem_device_id, Me_id, Test_datetime, Creation_id);
bool ResultHET = InsHealthETest(Hed_seq_id, PillBayNo, Test_datetime, Creation_id);
if (ResultHED == ResultHET == true)
return true;
else
return false;
}
this function did all data insertion trick for me i tested this service on the local mechine with ip address
http:72.44.151.178/PickPillService.asmx
then,
I see an example on how to attach asp.net web service to iphone apps
http://www.devx.com/wireless/Article/43209/0/page/4
then i created simillar code in xcode which has 2 files
ConsumePillServiceViewController.m
ConsumePillServiceViewController.h file
Now,
Using Designer of xcode i created 5 textboxes(Me_id,Mem_device_id,Test_datetime,Creation_id,PillBayNo) with all parameters hardcode as our service demands
then modify my ConsumePillServiceViewController.h file as follows
#interface ConsumePillServiceViewController : UIViewController {
//---outlets---
IBOutlet UITextField *Me_id;
IBOutlet UITextField *Mem_device_id;
IBOutlet UITextField *Test_datetime;
IBOutlet UITextField *Creation_id;
IBOutlet UITextField *PillBayNo;
//---web service access---
NSMutableData *webData;
NSMutableString *soapResults;
NSURLConnection *conn;
}
#property (nonatomic, retain) UITextField *Me_id;
#property (nonatomic, retain) UITextField *Mem_device_id;
#property (nonatomic, retain) UITextField *Test_datetime;
#property (nonatomic, retain) UITextField *Creation_id;
#property (nonatomic, retain) UITextField *PillBayNo;
- (IBAction)buttonClicked:(id)sender;
#end
and
ConsumePillServiceViewController.m as follows
#import "ConsumePillServiceViewController.h"
#implementation ConsumePillServiceViewController
#synthesize Me_id;
#synthesize Mem_device_id;
#synthesize Test_datetime;
#synthesize Creation_id;
#synthesize PillBayNo;
- (IBAction)buttonClicked:(id)sender {
NSString *soapMsg =
#"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<PickPill xml1ns=\"http://tempuri.org/\">";
NSString *smMe_id=
[soapMsg stringByAppendingString:
[NSString stringWithFormat:
#"<Me_id>%#</Me_id>",Me_id.text]];
NSString *smMem_device_id=
[smMe_id stringByAppendingString:
[NSString stringWithFormat:
#"<Mem_device_id>%#</Mem_device_id>",Mem_device_id.text]];
NSString *smTest_datetime=
[smMem_device_id stringByAppendingString:
[NSString stringWithFormat:
#"<Test_datetime>%#</Test_datetime>",Test_datetime.text]];
NSString *smCreation_id=
[smTest_datetime stringByAppendingString:
[NSString stringWithFormat:
#"<Creation_id>%#</Creation_id>",Creation_id.text]];
NSString *smPillBayNo=
[smCreation_id stringByAppendingString:
[NSString stringWithFormat:
#"<PillBayNo>%#</PillBayNo>",PillBayNo.text]];
NSString *smRestMsg=
[smPillBayNo stringByAppendingString:
#"</PickPill>"
"</soap:Body>" "</soap:Envelope>"];
soapMsg=smRestMsg;
//---print it to the Debugger Console for verification---
NSLog(soapMsg);
NSURL *url = [NSURL URLWithString: //create a URL load request object using instances :
#"http://72.44.151.178/PickPillService.asmx"];//of the NSMutableURLRequest and NSURL objects
NSMutableURLRequest *req =
[NSMutableURLRequest requestWithURL:url];
//opulate the request object with the various headers, such as Content-Type, SOAPAction, and Content-Length.
//You also set the HTTP method and HTTP body
NSString *msgLength =
[NSString stringWithFormat:#"%d", [soapMsg length]];
[req addValue:#"text/xml; charset=utf-8"
forHTTPHeaderField:#"Content-Type"];
[req addValue:#"http://tempuri.org/PickPill"
forHTTPHeaderField:#"SOAPAction"];
[req addValue:msgLength
forHTTPHeaderField:#"Content-Length"];
//---set the HTTP method and body---
[req setHTTPMethod:#"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; //establish the connection with the web service,
if (conn) { //you use the NSURLConnection class together with the request object just created
webData = [[NSMutableData data] retain];//webData object use to receive incoming data from the web service
}
}//End of button clicked event
-(void) connection:(NSURLConnection *) connection //Recive response
didReceiveResponse:(NSURLResponse *) response {
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection //Repeative call method and append data to webData
didReceiveData:(NSData *) data {
[webData appendData:data];
}
-(void) connection:(NSURLConnection *) connection//If error occure error should be displayed
didFailWithError:(NSError *) error {
[webData release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSLog(#"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
//---shows the XML---
NSLog(theXML);
[connection release];
[webData release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[Me_id release];
[Creation_id release];
[Mem_device_id release];
[Test_datetime release];
[PillBayNo release];
[soapResults release];
[super dealloc];
}
#end
I did all things as shown in the website and when i built application it successfully built
but in the debuggin window i see
(gdb) continue
2010-03-17 09:09:54.595 ConsumePillService[6546:20b] <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><PickPill xml1ns="http://tempuri.org/"><Me_id>A00000004303</Me_id><Mem_device_id>1011</Mem_device_id><Test_datetime>03/13/2010 07:34:38</Test_datetime><Creation_id>Hboxdata</Creation_id><PillBayNo>2</PillBayNo></PickPill></soap:Body></soap:Envelope>
(gdb) continue
(gdb) continue
(gdb) continue
2010-03-17 09:10:05.411 ConsumePillService[6546:20b] DONE. Received Bytes: 476
2010-03-17 09:10:05.412 ConsumePillService[6546:20b] <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Server was unable to process request. ---> One or more errors occurred during processing of command.
ORA-00936: missing expression</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
It should return me true if all things are ok
What is this ORA-00936 error all about
as it is not releted with webservice
Please help me solving this problem
Thanks in advance,
Vaibhav Deshpande