I thought i would share an example I made for my course for using objective c stuff to pull down text from a website and parse it out indie of ofxiphone.
testApp.h
#pragma once
#include "ofMain.h"
#include "ofxiPhone.h"
class testApp : public ofxiPhoneApp {
public:
void setup();
void update();
void draw();
void exit();
void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);
void lostFocus();
void gotFocus();
void gotMemoryWarning();
string NSStringToString(NSString * str);
vector<string> fileTxt;
};
testApp.mm
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);
// initialize the accelerometer
ofxAccelerometer.setup();
//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);
NSString *urlString = [NSString stringWithFormat: @"[http://www.swpc.noaa.gov/ftpdir/latest/DSD.txt"];](http://www.swpc.noaa.gov/ftpdir/latest/DSD.txt"];)
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSURLResponse *res = nil;
NSError *err = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];
NSString *s = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
fileTxt = ofSplitString(NSStringToString(s), " ");
for (int i = 1; i < fileTxt.size(); i++) {
fileTxt[i].erase(std::remove(fileTxt[i].begin(), fileTxt[i].end(), '\n'), fileTxt[i].end());
//cout << fileTxt[i] << endl;
int myNum = ofToInt(fileTxt[i]);
if (myNum == 2010) {
printf("2010 found \n");
}
}
[s release];
}
//-----------------------------------------------------------
string testApp::NSStringToString(NSString * str)
{
char newChars[ [str length]+1 ];
[str getCString:newChars];
return string(newChars);
}
//--------------------------------------------------------------
void testApp::update() {
}
//--------------------------------------------------------------
void testApp::draw() {
}
//--------------------------------------------------------------
void testApp::exit() {
}