typedef struct _protocol1
{
int type;
CGPoint pos;
} Protocol1;
-(void)sendData {
NSError *error;
Protocol1 msg;
msg.pos = ccp(100,100);
msg.type = 1;
NSData *packet = [NSData dataWithBytes:&msg length:sizeof(Protocol1)];
[self.myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataReliable error:&error];
if (error != nil)
{
NSLog(#"error"]);
}
}
That is a chunk of code from my project.
And I'm getting an error. However, I am unsure how to retrieve more information to help me debug. Can someone help me?
Sorry, I'm quite new with iOS development...
Using Cocos2d for a game.
EDIT
I am using the Simulator and my iPhone to test this. I doubt that is the problem, I already got the match working and everything...
To print out your error, try this!
NSLog(#"here is the error material: %#", [error localizedDescription])
if you have trouble, just click on NSError in your XCode4.
Then look at the right column, and click to get to the documentation.
(Or just search "NSError" in the Xcode documentation.)
Bring up "NSError Class Reference". It is very simple.
Be sure to look at the VARIOUS EXAMPLE CODE given.
For example scroll down to "localizedDescription" ad see the three sample codes. ("LazyTableImages, SeismicXML, URLCache")
You can download and look at the example projects. Search on "localizedDescription" and you'll see examples, if you're having trouble!
If you teach a man to fish ... Lol have fun.
Related
I am using the AssetsLibrary framework to retrieve all asset groups in the iPhone. I have some code snippet like this:
NSMutableArray *groups = [[NSMutableArray alloc] initWithCapacity:5];
void (^groupEnumerator)(ALAssetsGroup*, BOOL*) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
NSLog(#"Adding group %#", [group valueForProperty:ALAssetsGroupPropertyName]);
[groups addObject:group];
}
};
ALAssetsLibrary* library = [AssetsManager defaultAssetsLibrary];
[library enumerateGroupsWithTypes: ALAssetsGroupSavedPhotos
usingBlock:groupEnumerator
failureBlock:^(NSError * err) {NSLog(#"Erorr: %#", [err localizedDescription]);}];
And I found a weird behavior:
1) When I run my app in the iOS simulator (use command + R in Xcode), the groupEnumerator will be executed and group names will be printed in the console
2) I wrote some unit test for my app, when I run the unit test (use command + U in Xcode), which calls the above code snippet as it is called in my app, the groupEnumerator seems not get executed at all and none of the group name will be printed, and the failureBlock doesn't get called too and I don't get any error when running the tests but the group enumeration doesn't work as it does in the app.
I check Apple's documentation, and I know this method (enumerateGroupsWithTypes:usingBlock:failureBlock:) is asynchronous, however, even if I wait for a long time in my unit test, I don't see the groupEnumerator get executed.
I am testing against iOS 5.0 with Xcode 4.2.
Any help is appreciated. Thanks.
Stuck on this problem for several days, couldn't figure out the exact cause of this issue.
And instead of using OCUnit in Xcode 4, I had to switch to use gh-unit, which solves this issue actually. It seems related with the way Xcode 4 runs the test target.
http://gabriel.github.com/gh-unit
I'm following the suggestion in the answer here for redirecting NSLog output on an iOS device to a file, which works great. The problem is that it no longer shows up in the console on the device. What I'd really like is a way to tee the stderr stream to both the console and the file. Does anyone have an idea how to do that?
I found an acceptable answer on another thread (NSLog() to both console and file).
The solution provided there is to only redirect to a file if a debugger is not detected, like this:
if (!isatty(STDERR_FILENO))
{
// Redirection code
}
Thanks to Sailesh for that answer.
Once you freopen() the file descriptor, you can read from it and do as you please with the data. Some ideas from this will be useful to you.
You could either write it back out to stdout, or try to write directly to /dev/console. I've never tried to open /dev/console on an iPhone, but I'm guessing it's possible despite being outside of the sandbox. I'm not sure how the app review process will treat it.
Or you can redirect to a TCP socket and view on a remote telnet client. No need for XCode this way!
Basically:
Create a standard C function which calls an Obj-C static method:
void tcpLogg_log(NSString* fmt, ...)
{
va_list args;
va_start(args, fmt);
[TCPLogger tcpLog:fmt :args];
va_end(args);
}
The static Obj-C method:
(void)tcpLog:(NSString*)fmt :(va_list)args
{
NSLogv(fmt, args);
if(sharedSingleton != nil && sharedSingleton.socket != nil)
{
NSString *time = [sharedSingleton.dateFormat stringFromDate:[NSDate date]];
NSString *msg = [[NSString alloc] initWithFormat:fmt arguments:args];
mach_port_t tid = pthread_mach_thread_np(pthread_self());
NSString *str = [NSString stringWithFormat:#"%#[%X]: %#\r\n", time, tid, msg];
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[sharedSingleton.socket writeData:data
withTimeout:NETWORK_CLIENT_TIMEOUT_PERIOD
tag:0];
}
}
Then in your .pch file, add the following lines to override NSLog()
define NSLog(...) tcpLogg_log(__VA_ARGS__);
void tcpLogg_log(NSString* fmt, ...);
Of course more details are required to handle the TCP Socket. Working source code is available here:
https://github.com/driedler/iOS-TCP-Logger/wiki/About
i want to get data between xml tags? how to navigate? and get values..
im using wsdl2objc from google code:http://code.google.com/p/wsdl2objc/
output soapbody follows:
read instruction here: http://code.google.com/p/wsdl2objc/wiki/UsageInstructions
my header file: #import "MService.h"
how to get image source and text value????
please help me....
if([bodyPart isKindOfClass:[types_getFavoriteColorResponseType class]]) {
types_getFavoriteColorResponseType *body = (types_getFavoriteColorResponseType*)bodyPart;
// Now you can extract the color from the response
q.text = body.color;
continue;
}
Ок as far as I understand this is a part which extracts text data from your SOAP response.
BTW you need response to be processed via SAX or DOM? First example in given URL refers to DOM usage, whereas the second to SAX.
More than that I can not tell. Guess you have to read manual or find someone, who worked with this.
Use NSXMLParser, NSXMLParserDelegate for xml parsing, you can get the callbacks with proper values:
parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:foundCharacters:
parser:didEndElement:namespaceURI:qualifiedName:
Ref: http://developer.apple.com/library/ios/#documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
hey i got the result using sudzc.com
if ([result isKindOfClass:[MSalesPages class]]) {
NSLog(#"Response");
NSMutableArray* pageData = result.PageData;
for(MSalesPage* page in pageData){
NSLog(#"Inside for loop %#", page.Id);
NSMutableArray* images = page.Images;
NSMutableArray* textData = page.TextData;
for(MSalesImg* img in images){
NSLog(#"Image url %#",img.Src);
}
for(MSalesText* text in textData){
NSLog(#"Product Name %#",text.Value);
}
}
}
carefully check with the above xml, u will get the answer :)
I am programming an iPhone App which is supposed to parse a flat-file from the web, create managed objects from the flat-file and later on should display them in an UITableView.
There are no problems with the saving and the displaying, but I just can't get the hang of a good Parser.
Thats the file I want to parse: Flat-file
AS far as I know, I can't use the NSXMLParser for this task (because obviously there are no tags).
So I at first tried to programm a NSScanner which should get me the interesting properties --> didn't work out
Now I am using this method:
- (void) parseMemberDataWithURL: (NSString *)urlString
{
self.memberTempCounter = 1;
//Get data from web
self.downloadedText = [NSString stringWithContentsOfURL: [NSURL URLWithString: urlString] encoding:NSUTF8StringEncoding error:nil ];
memberArray = [downloadedText componentsSeparatedByString:#";"];
while (self.memberTempCounter<[memberArray count])
{
[[ExhibitorController sharedController] createExhibitorWithName:[memberArray objectAtIndex:self.memberTempCounter]
street:[memberArray objectAtIndex:self.memberTempCounter+2]
zip:[memberArray objectAtIndex:self.memberTempCounter+3]
city:[memberArray objectAtIndex:self.memberTempCounter+4]
email:[memberArray objectAtIndex:self.memberTempCounter+7]
phone:[memberArray objectAtIndex:self.memberTempCounter+5]
website:[memberArray objectAtIndex:self.memberTempCounter+8]
produktbereiche:[[memberArray objectAtIndex:self.memberTempCounter+9] componentsSeparatedByString:#","]];
self.memberTempCounter= self.memberTempCounter+13;
}
}
I am using the memberTempCounter to identify the property.
The problems are:
This only works out in like 3 of 4 times.1 of 4 times the App crashes and I have no Idea why...
The method has a performance like a 1962 VW Beetle. Parsing the whole chunk of data takes up to 3 Minutes on my iPhone 3G
Any Ideas or a simpler way to do this?
I would be really gratefull. Thanks in advance: -)
You might as well do all the parsing in the background, and then display as the information gets parsed.
As for memory issues, try doing temporary autorelease pools and release every 50 or so iterations through the loop.
int count = 0;
NSAutoreleasePool * loopPool = [[NSAutoreleasePool alloc] init];
while(someInsanelyLargeCondition){
// Do your stuff here
// .............
count++;
if (count > 50) {
count = 0;
[loopPool release];
loopPool = [[NSAutoreleasePool alloc] init];
}
}
Recursive-descent (LL1) parsers are pretty simple, light on memory, and for speed they go almost as fast as you can run a pointer through characters. Building your data structure would probably be the dominant time-taker.
I was finally able to fix my performance problem.
I have a method in another class, which ads Tags for the different Exhibitors. Therefore it first checks if the Tag already is stored in the database or else creates it.
With an growing Set of Tags in my database the search-process took longer and longer and this led to the long parsing time.
Anyone else having this problem: Take a look at the Performance Core Data Programming guide of apple in the "Implementing Find-or-Create Efficiently"-section:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html
I am trying to do search functionality in iPhone. I pass the page number and the string to be searched.. but it is not getting the proper output.
in contentStream I get nothing. I got this code by googling. I don't know what will be there in contentStream object.
-(BOOL)page:(CGPDFPageRef)inPage containsString:(NSString *)inSearchString {
[self setCurrentData:[NSMutableString string]];
CGPDFContentStreamRef contentStream = CGPDFContentStreamCreateWithPage(inPage);
CGPDFScannerRef scanner = CGPDFScannerCreate(contentStream, table, self);
bool ret = CGPDFScannerScan(scanner);
CGPDFScannerRelease(scanner);
CGPDFContentStreamRelease(contentStream);
return ([[currentData uppercaseString]
rangeOfString:[inSearchString uppercaseString]].location != NSNotFound);
}
If there is any other solution then also it is fine.
YOU SHOULD IMPLEMENT THE COMPLETE CODE
http://www.random-ideas.net/posts/42%22
check out the above link
a complete code to do so.
Check out this question and its answers for more information: PDF search on the iPhone