I'm sharing my string over the AppDelegate-Class:
SpeakersAppDelegate *mainDelegate = (SpeakersAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate setShareTex开发者_开发技巧t:xmlString];
And get the string back from the AppDelegate-Class:
SpeakersAppDelegate *mainDelegate = (SpeakersAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *xmlString = [mainDelegate getShareText];
With no problems if I use:
xmlString = @"<rsp><photos><photo url='xyz.jpg' thumb='xyz.jpg' /></photos></rsp>";
But the app crashes when I use (xmlString get's the content of the url correctly, the problem is the resiving of the string from AppDelegate-Class when xmlString is filled withContentFromURL):
xmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:url]];
Does anyone knows a solution? Thanks for help!
stringWithContentsOfURL:
returns an auto-released string. So when the autorelease pool is drained (usually when it's done processing the current event), your string is released. You then try to access it, and boom.
I suspect that your delegate is not managing the lifecycle of xmlString. You probably want setShareText:
to retain, or copy, the string. Be careful to release any previous string.
精彩评论