Search Results

Search found 1559 results on 63 pages for 'nslog'.

Page 7/63 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Custom NSView in NSMenuItem not receiving mouse events

    - by Dennis
    I have an NSMenu popping out of an NSStatusItem using popUpStatusItemMenu. These NSMenuItems show a bunch of different links, and each one is connected with setAction: to the openLink: method of a target. This arrangement has been working fine for a long time. The user chooses a link from the menu and the openLink: method then deals with it. Unfortunately, I recently decided to experiment with using NSMenuItem's setView: method to provide a nicer/slicker interface. Basically, I just stopped setting the title, created the NSMenuItem, and then used setView: to display a custom view. This works perfectly, the menu items look great and my custom view is displayed. However, when the user chooses a menu item and releases the mouse, the action no longer works (i.e., openLink: isn't called). If I just simply comment out the setView: call, then the actions work again (of course, the menu items are blank, but the action is executed properly). My first question, then, is why setting a view breaks the NSMenuItem's action. No problem, I thought, I'll fix it by detecting the mouseUp event in my custom view and calling my action method from there. I added this method to my custom view: - (void)mouseUp:(NSEvent *)theEvent { NSLog(@"in mouseUp"); } No dice! This method is never called. I can set tracking rects and receive mouseEntered: events, though. I put a few tests in my mouseEntered routine, as follows: if ([[self window] ignoresMouseEvents]) { NSLog(@"ignoring mouse events"); } else { NSLog(@"not ignoring mouse events"); } if ([[self window] canBecomeKeyWindow]) { dNSLog((@"canBecomeKeyWindow")); } else { NSLog(@"not canBecomeKeyWindow"); } if ([[self window] isKeyWindow]) { dNSLog((@"isKeyWindow")); } else { NSLog(@"not isKeyWindow"); } And got the following responses: not ignoring mouse events canBecomeKeyWindow not isKeyWindow Is this the problem? "not isKeyWindow"? Presumably this isn't good because Apple's docs say "If the user clicks a view that isn’t in the key window, by default the window is brought forward and made key, but the mouse event is not dispatched." But there must be a way do detect these events. HOW? Adding: [[self window] makeKeyWindow]; has no effect, despite the fact that canBecomeKeyWindow is YES.

    Read the article

  • TableView frame not resizing properly when pushing a new view controller and the keyboard is hiding

    - by Pete
    Hi, I must be missing something fundamental here. I have a UITableView inside of a NavigationViewController. When a table row is selected in the UITableView (using tableView:didSelectRowAtIndexPath:) I call pushViewController to display a different view controller. The new view controller appears correctly, but when I pop that view controller and return the UITableView is resized as if the keyboard was being displayed. I need to find a way to have the keyboard hide before I push the view controller so that the frame is restored correctly. If I comment out the code to push the view controller then the keyboard hides correctly and the frame resizes correctly. The code I use to show the keyboard is as follows: - (void) keyboardDidShowNotification:(NSNotification *)inNotification { NSLog(@"Keyboard Show"); if (keyboardVisible) return; // We now resize the view accordingly to accomodate the keyboard being visible keyboardVisible = YES; CGRect bounds = [[[inNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; bounds = [self.view convertRect:bounds fromView:nil]; CGRect tableFrame = tableViewNewEntry.frame; tableFrame.size.height -= bounds.size.height; // subtract the keyboard height if (self.tabBarController != nil) { tableFrame.size.height += 48; // add the tab bar height } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(shrinkDidEnd:finished:contextInfo:)]; tableViewNewEntry.frame = tableFrame; [UIView commitAnimations]; } The keyboard is hidden using: - (void) keyboardWillHideNotification:(NSNotification *)inNotification { if (!keyboardVisible) return; NSLog(@"Keyboard Hide"); keyboardVisible = FALSE; CGRect bounds = [[[inNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; bounds = [self.view convertRect:bounds fromView:nil]; CGRect tableFrame = tableViewNewEntry.frame; tableFrame.size.height += bounds.size.height; // add the keyboard height if (self.tabBarController != nil) { tableFrame.size.height -= 48; // subtract the tab bar height } tableViewNewEntry.frame = tableFrame; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(_shrinkDidEnd:finished:contextInfo:)]; tableViewNewEntry.frame = tableFrame; [UIView commitAnimations]; [tableViewNewEntry scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionMiddle animated:YES]; NSLog(@"Keyboard Hide Finished"); } I trigger the keyboard being hidden by resigning first responser for any control that is the first responder in ViewWillDisappear. I have added NSLog statements and see things happening in the log file as follows: Show Keyboard ViewWillDisappear: Hiding Keyboard Hide Keyboard Keyboard Hide Finished PushViewController (an NSLog entry at the point I push the new view controller) From this trace, I can see things happening in the right order, but It seems like when the view controller is pushed that the keyboard hide code does not execute properly. Any ideas would be really appreciated. I have been banging my head against the keyboard for a while trying to find out what I am doing wrong.

    Read the article

  • Problem with writeData

    - by zp26
    Hi, I have a problem with my code. I want to create a XML file like this: <name>myName<name> <x>myX<x> <y>myY<y> <z>myZ<z> but my file is: <name>myName<name><x>myX<x><y>myY<y><z>myZ<z> Can i have this text formatting? This is my code: -(void)salvataggioInXML:(NSString*)name:(float)x:(float)y:(float)z{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"filePosizioni.xml"]; NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath]; [myHandle seekToEndOfFile]; NSString *tagName = [NSString stringWithFormat:@"<name>%@<name>", name]; NSString *tagX = [NSString stringWithFormat:@"<x>%f<x>", name]; NSString *tagY = [NSString stringWithFormat:@"<y>%f<y>", name]; NSString *tagZ = [NSString stringWithFormat:@"<z>%f<z>", name]; NSData* dataName = [tagName dataUsingEncoding: NSASCIIStringEncoding]; NSData* dataX = [tagX dataUsingEncoding: NSASCIIStringEncoding]; NSData* dataY = [tagY dataUsingEncoding: NSASCIIStringEncoding]; NSData* dataZ = [tagZ dataUsingEncoding: NSASCIIStringEncoding]; [myHandle writeData:dataName]; NSLog(@"writeok"); [myHandle seekToEndOfFile]; [myHandle writeData:dataX]; NSLog(@"writeok"); [myHandle seekToEndOfFile]; [myHandle writeData:dataY]; NSLog(@"writeok"); [myHandle seekToEndOfFile]; [myHandle writeData:dataZ]; NSLog(@"writeok"); [myHandle seekToEndOfFile]; NSLog(@"zp26 %@",filePath); }

    Read the article

  • Unbalanced calls to begin/end appearance transitions for <ViewController>,<Tab>

    - by onkar
    I am trying to implement Tabs into my secondView.On button touch(from ViewController.m) I am navigating to secondView(Tabs). In my Tabs.xib file I have added a TabBar at bottom and it is custom class of UITabBar. ViewController.m - (IBAction)touchedInside:(id)sender { NSLog(@"touhced up inside"); Tabs *temp = [[Tabs alloc]initWithNibName:@"Tabs" bundle:nil]; [self.navigationController pushViewController:temp animated:YES]; [self presentViewController:temp animated:YES completion:nil]; } Tabs.m - (void)viewDidLoad { [super viewDidLoad]; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; UITabBarController *tabBarController = [[UITabBarController alloc]init]; /* Tab_1 *firstView = [[Tab_1 alloc] init]; UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"First" image:nil tag:1]; [firstView setTabBarItem:item1]; NSLog(@"after first tab is added"); Tab_2 *secondView = [[Tab_2 alloc] init]; UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"Sec" image:nil tag:1] ; [secondView setTabBarItem:item2]; NSLog(@"after second tab is added"); [tabBarController setViewControllers:[NSArray arrayWithObjects:firstView,secondView,nil] animated:NO]; NSLog(@"after tab is added"); [appDelegate.window addSubview:tabBarController.view]; NSLog(@"after view is added"); */ appDelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. UIViewController *viewController1 = [[Tab_1 alloc] initWithNibName:@"Tab 1" bundle:nil]; UIViewController *viewController2 = [[Tab_2 alloc] initWithNibName:@"Tab 2" bundle:nil]; UIViewController *viewController3 = [[Tab_2 alloc] initWithNibName:@"Tab 1" bundle:nil]; tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil]; appDelegate.window.rootViewController = self.tabBarController; [appDelegate.window makeKeyAndVisible]; Tabs *temp = [[Tabs alloc]initWithNibName:@"Tabs" bundle:nil]; [self.navigationController presentModalViewController:temp animated:NO]; } Errors Unbalanced calls to begin/end appearance transitions for <ViewController: 0x6833c80>. 2012-12-06 09:57:48.963 demoTabs[667:f803] Unbalanced calls to begin/end appearance transitions for <Tabs: 0x6a3fc90>.

    Read the article

  • iPhone OS: KVO: Why is my Observer only getting notified at applicationDidfinishLaunching

    - by nickthedude
    I am basically trying to implement an achievement tracking setup in my app. I have a managedObjectModel class called StatTracker to keep track of all sorts of stats and I want my Achievement tracking class to be notified when those stats change so I can check them against a value and see if the user has earned an achievement. I've tried to impliment KVO and I think I'm pretty close to making it happen but the problem I'm running into is this: So in the appDelegate i have an Ivar for my Achievement tracker class, I attach it as an observer to a property value of my statTracker core data entity in the applicationDidFinishLaunching method. I know its making the connection because I've been able to trigger a UIAlert in my AchievementTracker instance, and I've put several log statements that should be triggered whenever the value on the StatTracker's property changes. the log statement appears only once at the application launch. I'm wondering if I'm missing something in the whole object lifecycle scheme of things, I just don't understand why the observer stops getting notified of changes after the applicationDidFinishLaunching method has run. Does it have something to do with the scope of the AchievementTracker reference or more likely the reference to my core data StatTracker is going away once that method finishes up. I guess I'm not sure the right place to place these if that is the case. Would love some help. Here is the code where I add the observer in my appDidFinishLaunching method: [[CoreDataSingleton sharedCoreDataSingleton] incrementStatTrackerStat:@"timesLaunched"]; achievementsObserver = [[AchievementTracker alloc] init]; StatTracker *object = nil; object = [[[CoreDataSingleton sharedCoreDataSingleton] getStatTracker] objectAtIndex:0]; NSLog(@"%@",[object description]); [[CoreDataSingleton sharedCoreDataSingleton] addObserver:achievementsObserver toStat:@"refreshCount"]; here is the code in my core data singleton: -(void) addObserver:(id)observer toStat:(NSString *) statToObserve { NSLog(@"observer added"); NSArray *array = [[NSArray alloc] init]; array = [self getStatTracker]; [[array objectAtIndex:0] addObserver:observer forKeyPath:statToObserve options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL]; } and my AchievementTracker: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"achievemnt hit"); //NSLog("%@", [change description]); if ([keyPath isEqual:@"refreshCount"] && ((NSInteger)[change valueForKey:@"NSKeyValueObservingOptionOld"] == 60) ) { NSLog(@"achievemnt hit inside"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"achievement unlocked" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil]; [alert show]; } }

    Read the article

  • Getting RSSIValue from IOBluetoothHostController

    - by Tanner Ezell
    I'm trying to write a simple application that gathers the RSSIValue and displays it via NSLog, my code is as follows: #import <Foundation/Foundation.h> #import <Cocoa/Cocoa.h> #import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h> #import <IOBluetooth/objc/IOBluetoothDevice.h> #import <IOBluetooth/objc/IOBluetoothHostController.h> #import <IOBluetooth/IOBluetoothUtilities.h> @interface getRSSI: NSObject {} -(void) readRSSIForDeviceComplete:(id)controller device:(IOBluetoothDevice*)device info:(BluetoothHCIRSSIInfo*)info error:(IOReturn)error; @end @implementation getRSSI - (void) readRSSIForDeviceComplete:(id)controller device:(IOBluetoothDevice*)device info:(BluetoothHCIRSSIInfo*)info error:(IOReturn)error { if (error != kIOReturnSuccess) { NSLog(@"readRSSIForDeviceComplete return error"); CFRunLoopStop(CFRunLoopGetCurrent()); } if (info->handle == kBluetoothConnectionHandleNone) { NSLog(@"readRSSIForDeviceComplete no handle"); CFRunLoopStop(CFRunLoopGetCurrent()); } NSLog(@"RSSI = %i dBm ", info->RSSIValue); [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 5]]; [device closeConnection]; [device openConnection]; [controller readRSSIForDevice:device]; } @end int main (int argc, const char * argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"start"); IOBluetoothHostController *hci = [IOBluetoothHostController defaultController]; NSString *addrStr = @"xx:xx:xx:xx:xx:xx"; BluetoothDeviceAddress addr; IOBluetoothNSStringToDeviceAddress(addrStr, &addr); IOBluetoothDevice *device = [[IOBluetoothDevice alloc] init]; device = [IOBluetoothDevice withAddress:&addr]; [device retain]; [device openConnection]; getRSSI *rssi = [[getRSSI alloc] init]; [hci setDelegate:rssi]; [hci readRSSIForDevice:device]; CFRunLoopRun(); [hci release]; [rssi release]; [pool release]; return 0; } The problem I am facing is that the readRSSIForDeviceComplete seems to work just fine, info passes along a value. The problem is that the RSSI value is drastically different from the one I can view from OS X via option clicking the bluetooth icon at the top. It is typical for my application to print off 1,2,-1,-8,etc while the menu displays -64 dBm, -66, -70, -42, etc. I would really appreciate some guidance.

    Read the article

  • Using NSXMLParser to parse Vimeo XML on iPhone.

    - by Sonny Fazio
    Hello, I'm working on an iPhone app that will use Vimeo Simple API to give me a listing our videos by a certain user, in a convenient TableView format. I'm new to Parsing XML and have tried TouchXML, TinyXML, and now NSXMLParser with no luck. Most tutorials on parsing XML are for a blog, and not for an API XML sheet. I've tried modifying the blog parsers to search for the specific tags, but it doesn't seem to work. Right now I'm working with NSXMLParser and it seems to correctly find the value of an XML tag, but when it goes to append it to a NSMutableString, it writes a whole bunch of nulls in between it. I'm using a tutorial from theappleblog and modifying it to work with Vimeo API - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if ([currentElement isEqualToString:@"video_title"]) { NSLog(@"String: %@",string); [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"video_url"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"video_description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"date"]) { [currentDate appendString:string]; } Here is the nulls it writes: http://grab.by/grabs/92d9cfc2df4fac3fe6579493b1a8e89f.png Then when it finishes, it has to add the NSMutableStrings into a NSMutableDictionary - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ NSLog(@"Title: %@",currentTitle); if ([elementName isEqualToString:@"item"]) {// save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"video_title"]; NSLog(@"Current Title%@", currentTitle); [item setObject:currentLink forKey:@"video_url"]; [item setObject:currentSummary forKey:@"video_description"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } I would really appreciate it if someone has any advance

    Read the article

  • Core-Data Can't pass managedObjectContext from app delegate to view controller

    - by yahuie
    I'm making a core-data application that is view based. I can create the managedObjectContext and 'use' it in the app delegate, but can not pass it to the mainviewcontroller. Probably something simple, but I can't find the problem after looking for quite a while. The managedObjectModel is nil in the mainviewcontroller. The log and error is here: 2010-06-02 11:01:10.504 TestCoreData[404:207] Could not make MOC in MainViewController implementation. 2010-06-02 11:01:10.505 TestCoreData[404:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Shelf'' 2010-06-02 11:01:10.506 TestCoreData[404:207] Stack: ( 30864475, 2452296969, 28852395, 12038, 3217218, 10258, 2700679, 2738614, 2726708, 2709119, 2736225, 38960473, 30649216, 30645320, 2702869, 2740143, 9704, 9558 ) (gdb) Code for app delegate here: -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil]; self.mainViewController = aController; [aController release]; NSLog(@"before did finish launching"); if (self.managedObjectContext == nil) { NSLog(@"Could not make MOC in TestCoreDataAppDelegate implementation."); } //Just to see if I can access the here. NSFetchRequest* request = [[NSFetchRequest alloc] init]; NSEntityDescription* entity = [NSEntityDescription entityForName:@"Shelf" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; if (!entity) { NSLog(@"No Entity in TestCoreDataAppDelegate didfinishlaunching"); } NSLog(@"passed did finish launching"); NSManagedObjectContext *context = [self managedObjectContext]; self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame; self.mainViewController.managedObjectContext = context; [context release]; [window addSubview:[mainViewController view]]; [window makeKeyAndVisible]; return YES; } Code in MainViewController here: @implementation MainViewController @synthesize managedObjectContext; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; if (self.managedObjectContext == nil) { NSLog(@"Could not make MOC in MainViewController implementation."); } NSFetchRequest* request = [[NSFetchRequest alloc] init]; NSEntityDescription* entity = [NSEntityDescription entityForName:@"Shelf" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; } Thanks.

    Read the article

  • Download a file using cocoa

    - by dododedodonl
    Hi All, I want to download a file to the downloads folder. I searched google for this and found the NSURLDownload class. I've read the page in the dev center and created this code (with some copy and pasting) this code: @implementation Downloader @synthesize downloadResponse; - (void)startDownloadingURL:(NSString*)downloadUrl destenation:(NSString*)destenation { // create the request NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLDownload *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self]; if (!theDownload) { NSLog(@"Download could not be made..."); } } - (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename { NSString *destinationFilename; NSString *homeDirectory=NSHomeDirectory(); destinationFilename=[[homeDirectory stringByAppendingPathComponent:@"Desktop"] stringByAppendingPathComponent:filename]; [download setDestination:destinationFilename allowOverwrite:NO]; } - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { // release the connection [download release]; // inform the user NSLog(@"Download failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); } - (void)downloadDidFinish:(NSURLDownload *)download { // release the connection [download release]; // do something with the data NSLog(@"downloadDidFinish"); } - (void)setDownloadResponse:(NSURLResponse *)aDownloadResponse { [aDownloadResponse retain]; [downloadResponse release]; downloadResponse = aDownloadResponse; } - (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response { // reset the progress, this might be called multiple times bytesReceived = 0; // retain the response to use later [self setDownloadResponse:response]; } - (void)download:(NSURLDownload *)download didReceiveDataOfLength:(unsigned)length { long long expectedLength = [[self downloadResponse] expectedContentLength]; bytesReceived = bytesReceived+length; if (expectedLength != NSURLResponseUnknownLength) { percentComplete = (bytesReceived/(float)expectedLength)*100.0; NSLog(@"Percent - %f",percentComplete); } else { NSLog(@"Bytes received - %d",bytesReceived); } } -(NSURLRequest *)download:(NSURLDownload *)download willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse { NSURLRequest *newRequest=request; if (redirectResponse) { newRequest=nil; } return newRequest; } @end But my problem is now, it doesn't appear on the desktop as specified. And I want to put it in downloads and not on the desktop... What do I have to do?

    Read the article

  • How to convert m4a file to aac adts file in Xcode?

    - by Bird Hsuie
    I have a mp4 file copied from iPod lib and saved to my Document for my next step, I need it to convert to .mp3 or .aac(ADTS type) I use this code and failed... -(IBAction)compressFile:(id)sender{ NSLog (@"handleConvertToPCMTapped"); // open an ExtAudioFile NSLog (@"opening %@", exportURL); ExtAudioFileRef inputFile; CheckResult (ExtAudioFileOpenURL((__bridge CFURLRef)exportURL, &inputFile), "ExtAudioFileOpenURL failed"); // prepare to convert to a plain ol' PCM format AudioStreamBasicDescription myPCMFormat; myPCMFormat.mSampleRate = 44100; // todo: or use source rate? myPCMFormat.mFormatID = kAudioFormatMPEGLayer3 ; myPCMFormat.mFormatFlags = kAudioFormatFlagsCanonical; myPCMFormat.mChannelsPerFrame = 2; myPCMFormat.mFramesPerPacket = 1; myPCMFormat.mBitsPerChannel = 16; myPCMFormat.mBytesPerPacket = 4; myPCMFormat.mBytesPerFrame = 4; CheckResult (ExtAudioFileSetProperty(inputFile, kExtAudioFileProperty_ClientDataFormat, sizeof (myPCMFormat), &myPCMFormat), "ExtAudioFileSetProperty failed"); // allocate a big buffer. size can be arbitrary for ExtAudioFile. // you have 64 KB to spare, right? UInt32 outputBufferSize = 0x10000; void* ioBuf = malloc (outputBufferSize); UInt32 sizePerPacket = myPCMFormat.mBytesPerPacket; UInt32 packetsPerBuffer = outputBufferSize / sizePerPacket; // set up output file NSString *outputPath = [myDocumentsDirectory() stringByAppendingPathComponent:@"m_export.mp3"]; NSURL *outputURL = [NSURL fileURLWithPath:outputPath]; NSLog (@"creating output file %@", outputURL); AudioFileID outputFile; CheckResult(AudioFileCreateWithURL((__bridge CFURLRef)outputURL, kAudioFileCAFType, &myPCMFormat, kAudioFileFlags_EraseFile, &outputFile), "AudioFileCreateWithURL failed"); // start convertin' UInt32 outputFilePacketPosition = 0; //in bytes while (true) { // wrap the destination buffer in an AudioBufferList AudioBufferList convertedData; convertedData.mNumberBuffers = 1; convertedData.mBuffers[0].mNumberChannels = myPCMFormat.mChannelsPerFrame; convertedData.mBuffers[0].mDataByteSize = outputBufferSize; convertedData.mBuffers[0].mData = ioBuf; UInt32 frameCount = packetsPerBuffer; // read from the extaudiofile CheckResult (ExtAudioFileRead(inputFile, &frameCount, &convertedData), "Couldn't read from input file"); if (frameCount == 0) { printf ("done reading from file"); break; } // write the converted data to the output file CheckResult (AudioFileWritePackets(outputFile, false, frameCount, NULL, outputFilePacketPosition / myPCMFormat.mBytesPerPacket, &frameCount, convertedData.mBuffers[0].mData), "Couldn't write packets to file"); NSLog (@"Converted %ld bytes", outputFilePacketPosition); // advance the output file write location outputFilePacketPosition += (frameCount * myPCMFormat.mBytesPerPacket); } // clean up ExtAudioFileDispose(inputFile); AudioFileClose(outputFile); // show size in label NSLog (@"checking file at %@", outputPath); [self transMitFile:outputPath]; if ([[NSFileManager defaultManager] fileExistsAtPath:outputPath]) { NSError *fileManagerError = nil; unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:outputPath error:&fileManagerError] fileSize]; } any suggestion?.......thanks for your great help!

    Read the article

  • NSUrlconnection problem receiving data from some filehosts

    - by Tammo
    hello again, i am trying to develop an downloadmanager. i can now download files from almost anywhere on linkclick. in the - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType i check if the url is a url to a binaryfile like a zipfile. than i setup a nsurlconnection NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [urlRequest setValue:@"User-Agent" forHTTPHeaderField:@"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3"]; NSURLConnection *mainConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self]; if (nil == mainConnection) { NSLog(@"Could not create the NSURLConnection object"); } (void)connection:(NSURLConnection )connection didReceiveResponse:(NSURLResponse)response { self.tabBarController.selectedIndex=1; [receivedData setLength:0]; percent = 0; localFilename = [[[url2 absoluteString] lastPathComponent] copy]; NSLog(localFilename); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0] ; NSString *appFile = [documentsDirectory stringByAppendingPathComponent:localFilename]; [[NSFileManager defaultManager] createFileAtPath:appFile contents:nil attributes:nil]; [downloadname setHidden:NO]; [downloadname setText:localFilename]; expectedBytes = [response expectedContentLength]; exp = [response expectedContentLength]; NSLog(@"content-length: %lli Bytes", expectedBytes); file = [[NSFileHandle fileHandleForUpdatingAtPath:appFile] retain]; if (file) { [file seekToEndOfFile]; } } (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { if (file) { [file seekToEndOfFile]; } [file writeData:data]; [receivedData appendData:data]; long long resourceLength = [receivedData length]; float res = [receivedData length]; percent = res/exp; [progress setHidden:NO]; [progress setProgress:percent]; NSLog(@"Remaining: %lli KB", (expectedBytes-resourceLength)/1024); [kbleft setHidden:NO]; [kbleft setText:[NSString stringWithFormat:@"%lli / %lli KB", expectedBytes/1024 ,(resourceLength)/1024]]; } in the connectiondidfinish loading i close the file. all working fine for nearly every hoster except hosters wich have a capture procedure before like filedude.com in the uiwebview i can surf to the downloadpage enter the captcha and get the downloadlink. when i click on it the file will be created in the documentsdir with the filename and the download starts but he dont get any data. every file has 0kb and the NSLog(@"content-length: %lli Bytes", expectedBytes); gives out something like 100-400 byte . can somebody help me solve this problem? kind regards

    Read the article

  • Issue with DFS imlemtation in objetive-c

    - by Hemant
    i am trying to to do something like this Below is my code: -(id) init{ if( (self=[super init]) ) { bubbles_Arr = [[NSMutableArray alloc] initWithCapacity: 9]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"1",@"1",@"1",@"1",@"1",nil] atIndex:0]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"3",@"3",@"5",@"5",@"1",nil] atIndex:1]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"3",@"5",@"3",@"1",nil] atIndex:2]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"3",@"5",@"3",@"1",nil] atIndex:3]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"1",@"1",@"1",@"1",@"1",nil] atIndex:4]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"5",@"3",@"5",@"1",nil] atIndex:5]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"5",@"5",@"5",@"5",nil] atIndex:6]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"5",@"5",@"5",@"5",nil] atIndex:7]; [bubbles_Arr insertObject:[NSMutableArray arrayWithObjects:@"5",@"5",@"5",@"5",@"5",nil] atIndex:8]; NOCOLOR = @"-1"; R = 9; C = 5; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(testting) userInfo:Nil repeats:NO]; } return self; } -(void)testting{ // NSLog(@"dataArray---- %@",dataArray.description); int startR = 0; int startC = 0; int color = 1 ;// red // NSString *color = @"5"; //reset visited matrix to false. for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) visited[i][j] = FALSE; //reset count count = 0; [self dfs:startR :startC :color :false]; NSLog(@"count--- %d",count); NSLog(@"test--- %@",bubbles_Arr); } -(void)dfs:(int)ro:(int)co:(int)colori:(BOOL)set{ for(int dr = -1; dr <= 1; dr++) for(int dc = -1; dc <= 1; dc++) if((dr == 0 ^ dc == 0) && [self ok:ro+dr :co+dc]) // 4 neighbors { int nr = ro+dr; int nc = co+dc; NSLog(@"-- %d ---- %d",[[[bubbles_Arr objectAtIndex:nr] objectAtIndex:nc] integerValue],colori); if ((([[[bubbles_Arr objectAtIndex:nr] objectAtIndex:nc] integerValue]==1 || [[[bubbles_Arr objectAtIndex:nr] objectAtIndex:nc] isEqualToString:@"1"]) && !visited[nr][nc])) { visited[nr][nc] = true; count++; [self dfs:nr :nc :colori :set]; if(count>2) { [[bubbles_Arr objectAtIndex:nr] replaceObjectAtIndex:nc withObject:NOCOLOR]; [bubbles[nc+1][nr+1] setTexture:[[CCTextureCache sharedTextureCache] addImage:@"gray_tiger.png"]]; } } } } -(BOOL)ok:(int)r:(int)c{ return r >= 0 && r < R && c >= 0 && c < C; } But it's only working for left to right,not working for right to left. And it is also skipping first object. Thanks in advance.

    Read the article

  • xml parsing using nsxmlParser in iphone

    - by filthynight
    hi all, I have a problem in parsing xml from google api, the api xml looks like this ....... Now the problem is that first of all, the tags are different, like first parent tag name is "abc" and second parent tag is "efg", further more the inner tags are different as well. i have modified code got from web that it parses another url, but in this case since the tags keeps on changing it does not work. the url = "http://www.google.com/ig/api?weather=anaheim,ca" Source Code (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); if (currentElement) { [currentElement release]; currentElement = nil; } currentElement = [elementName copy]; NSString *thisOwner = [attributeDict objectForKey:@"data"]; NSLog(@"element Name-------: %@", thisOwner); if ([elementName isEqualToString:@"forecast_information"]) //|| [elementName isEqualToString:@"current_conditions"] || [elementName isEqualToString:@"forecast_conditions"]) { // clear out our story item caches... //NSString *nm = [[attributeDict objectForKey:@"city"] stringValue]; //NSLog(@"value...%@",nm); item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; [item setObject:currentLink forKey:@"postal_code"]; [item setObject:currentSummary forKey:@"current_date_time"]; [item setObject:currentDate forKey:@"unit_system"]; NSLog(@"adding story: %@", currentTitle); [stories addObject:[item copy]]; } } I have another function didEndElement where the values are assigned in the array, but i could not figure out how to assign values of an attribute. Can somebody please help me in this regards Thanks!

    Read the article

  • Using NSXMLParser with CDATA

    - by Robb
    I'm parsing an RSS feed with NSXMLParser and it's working fine for the title and other strings but one of the elements is an image thats like <!CDATA <a href="http:image..etc> How do I add that as my cell image in my table view? Would I define that as an image type? This is what i'm using to do my parsing: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [ [NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ //NSLog(@"ended element: %@", elementName); if ([elementName isEqualToString:@"item"]) { // save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"title"]; [item setObject:currentLink forKey:@"link"]; [item setObject:currentSummary forKey:@"description"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([currentElement isEqualToString:@"title"]) { [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"link"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"pubDate"]) { [currentDate appendString:string]; } }

    Read the article

  • iPhone UnitTesting UITextField value and otest error 133

    - by Justin Galzic
    Are UITextFields not meant to be part of the LogicTests and instead part of the ApplicationTest target? I have a factory class that is responsible for creating and returning an (iPhone) UITextField and I'm trying to unit test it. It is part of my Logic Test target and when I try to build and run the tests, I get a build error about: /Developer/Tools/RunPlatformUnitTests.include:451:0 Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/ 'Developer/usr/bin/otest' exited abnormally with code 133 (it may have crashed). In the build window, this points to the following line in: "RunPlatformUnitTests.include" RPUTIFail ${LINENO} "Test rig '${TEST_RIG}' exited abnormally with code ${TEST_RIG_RESULT} (it may have crashed)." My unit test looks like this: #import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> // Test-subject headers. #import "TextFieldFactory.h" @interface TextFieldFactoryTests : SenTestCase { } @end @implementation TextFieldFactoryTests #pragma mark Test Setup/teardown - (void) setUp { NSLog(@"%@ setUp", self.name); } - (void) tearDown { NSLog(@"%@ tearDown", self.name); } #pragma mark Tests - (void) testUITextField_NotASecureField { NSLog(@"%@ start", self.name); UITextField *textField = [TextFieldFactory createTextField:YES]; NSLog(@"%@ end", self.name); } The class I'm trying to test: // Header file #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface TextFieldFactory : NSObject { } +(UITextField *)createTextField:(BOOL)isSecureField; @end // Implementation file #import "TextFieldFactory.h" @implementation TextFieldFactory +(UITextField *)createTextField:(BOOL)isSecureField { // x,y,z,w are constants declared else where UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(x, y, z, w)] autorelease]; // some initialization code return textField; } @end

    Read the article

  • MKMapView loading all annotation views at once (including those that are outside the current rect)

    - by jmans
    Has anyone else run into this problem? Here's the code: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(WWMapAnnotation *)annotation { // Only return an Annotation view for the placemarks. Ignore for the current location--the iPhone SDK will place a blue ball there. NSLog(@"Request for annotation view"); if ([annotation isKindOfClass:[WWMapAnnotation class]]){ MKPinAnnotationView *browse_map_annot_view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"BrowseMapAnnot"]; if (!browse_map_annot_view) { browse_map_annot_view = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"BrowseMapAnnot"] autorelease]; NSLog(@"Creating new annotation view"); } else { NSLog(@"Recycling annotation view"); browse_map_annot_view.annotation = annotation; } ... As soon as the view is displayed, I get 2009-08-05 13:12:03.332 xxx[24308:20b] Request for annotation view 2009-08-05 13:12:03.333 xxx[24308:20b] Creating new annotation view 2009-08-05 13:12:03.333 xxx[24308:20b] Request for annotation view 2009-08-05 13:12:03.333 xxx[24308:20b] Creating new annotation view and on and on, for every annotation (~60) I've added. The map (correctly) only displays the two annotations in the current rect. I am setting the region in viewDidLoad: if (center_point.latitude == 0) { center_point.latitude = 35.785098; center_point.longitude = -78.669899; } if (map_span.latitudeDelta == 0) { map_span.latitudeDelta = .001; map_span.longitudeDelta = .001; } map_region.center = center_point; map_region.span = map_span; NSLog(@"Setting initial map center and region"); [browse_map_view setRegion:map_region animated:NO]; The log entry for the region being set is printed to the console before any annotation views are requested. The problem here is that since all of the annotations are being requested at once, [mapView dequeueReusableAnnotationViewWithIdentifier] does nothing, since there are unique MKAnnotationViews for every annotation on the map. This is leading to memory problems for me. One possible issue is that these annotations are clustered in a pretty small space (~1 mile radius). Although the map is zoomed in pretty tight in viewDidLoad (latitude and longitude delta .001), it still loads all of the annotation views at once. Thanks...

    Read the article

  • Images in the project NOT adding to array - don't know why.

    - by Sam Jarman
    Hi there, I have to sets of images. Each set has 16 images. One set is called 0.png through to 15.png the other is a0.png through to a15.png. In my app, it loads each one dependent on a variable (which by logging, I have proved it works) here is the code [MemoryManager sharedMemoryManager]; NSLog(@"THEME: %@", [MemoryManager sharedMemoryManager].themeName); imageArray = [[NSMutableArray alloc] init]; if([MemoryManager sharedMemoryManager].themeName == @"hand"){ NSLog(@"Here 2"); [imageArray addObject:[UIImage imageNamed:@"0.png"]]; // [imageArray addObject:[UIImage imageNamed:@"1.png"]];//1 [imageArray addObject:[UIImage imageNamed:@"2.png"]];//2 [imageArray addObject:[UIImage imageNamed:@"3.png"]];//3 [imageArray addObject:[UIImage imageNamed:@"4.png"]];//4 [imageArray addObject:[UIImage imageNamed:@"5.png"]];//5 [imageArray addObject:[UIImage imageNamed:@"6.png"]];//6 [imageArray addObject:[UIImage imageNamed:@"7.png"]];//7 [imageArray addObject:[UIImage imageNamed:@"8.png"]];//8 [imageArray addObject:[UIImage imageNamed:@"9.png"]];//9 [imageArray addObject:[UIImage imageNamed:@"10.png"]];//10 [imageArray addObject:[UIImage imageNamed:@"11.png"]];//11 [imageArray addObject:[UIImage imageNamed:@"12.png"]];//12 [imageArray addObject:[UIImage imageNamed:@"13.png"]];//13 [imageArray addObject:[UIImage imageNamed:@"14.png"]];//14 [imageArray addObject:[UIImage imageNamed:@"15.png"]];//15 } if([MemoryManager sharedMemoryManager].themeName == @"letters"){ NSLog(@"Here 3"); //[imageArray removeAllObjects]; [imageArray addObject:[UIImage imageNamed:@"a0.png"]]; // [imageArray addObject:[UIImage imageNamed:@"a1.png"]];//1 [imageArray addObject:[UIImage imageNamed:@"a2.png"]];//2 [imageArray addObject:[UIImage imageNamed:@"a3.png"]];//3 [imageArray addObject:[UIImage imageNamed:@"a4.png"]];//4 [imageArray addObject:[UIImage imageNamed:@"a5.png"]];//5 [imageArray addObject:[UIImage imageNamed:@"a6.png"]];//6 [imageArray addObject:[UIImage imageNamed:@"a7.png"]];//7 [imageArray addObject:[UIImage imageNamed:@"a8.png"]];//8 [imageArray addObject:[UIImage imageNamed:@"a9.png"]];//9 [imageArray addObject:[UIImage imageNamed:@"a10.png"]];//10 [imageArray addObject:[UIImage imageNamed:@"a11.png"]];//11 [imageArray addObject:[UIImage imageNamed:@"a12.png"]];//12 [imageArray addObject:[UIImage imageNamed:@"a13.png"]];//13 [imageArray addObject:[UIImage imageNamed:@"a14.png"]];//14 [imageArray addObject:[UIImage imageNamed:@"a15.png"]];//15 NSLog(@"Here 4"); } The log says 2010-05-26 21:30:57.092 Memory[22155:207] Here 1 2010-05-26 21:30:57.093 Memory[22155:207] THEME: letters 2010-05-26 21:30:57.095 Memory[22155:207] Here 3 2010-05-26 21:30:57.109 Memory[22155:207] Here 4 The images are in the same folder the .xproj file is. They simply is just not working. Any ideas? Cheers

    Read the article

  • iPhone JSON object releasing itself?

    - by MidnightLightning
    I'm using the JSON Framework addon for iPhone's Objective-C to catch a JSON object that's an array of Dictionary-style objects via HTTP. Here's my connectionDidFinishLoading function: - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; [loadingIndicator stopAnimating]; NSArray *responseArray = [responseString JSONValue]; // Grab the JSON array of dictionaries NSLog(@"Response Array: %@", responseArray); if ([responseArray respondsToSelector:@selector(count)]) { NSLog(@"Returned %@ items", [responseArray count]); } [responseArray release]; [responseString release]; } The issue is that the code is throwing a EXC_BAD_ACCESS error on the second NSLog line. The EXC_BAD_ACCESS error I think indicates that the variable got released from memory, but the first NSLog command works just fine (and shows that the data is all there); it seems that only when calling the count message is causing the error, but the respondsToSelector call at least thinks that the responseArray should be able to respond to that message. When running with the debugger, it crashes on that second line, but the stack shows that the responseArray object is still defined, and has 12 objects in it (so the debugger at least is able to get an accurate count of the contents of that variable). Is this a problem with the JSON framework's creation of that NSArray, or is there something wrong with my code?

    Read the article

  • iphone cannot rotate views in TabBar controller

    - by Luc
    Hello, I am working on an application that consists of a TabBar controller. Within on of its tab, I have a subclass of UITableViewController, within this list I have a Core-plot graph in the first cell and some other data in the 4 following cells. When I return YES in the shouldAutorotateToInterfaceOrientation method, I would expect the autoresizing of the list view to happen, but... nothing. When I add some log in the willRotateToInterfaceOrientation method, they are not displayed. Is there something I missed ? Thanks a lot, Luc // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations //return (interfaceOrientation == UIInterfaceOrientationPortrait); NSLog(@"Orientation"); return YES; } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; NSLog(@"Rotating"); if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { NSLog(@"view land:%@", self.view); } if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { NSLog(@"view portrait:%@", self.view); } }

    Read the article

  • AVAudioPlayer only initializes with some files

    - by Brendan
    Hi everyone, I'm having trouble playing some files with AVAudioPlayer. When I try to play a certain m4a, it works fine. It also works with an mp3 that I try. However it fails on one particular mp3 every time (15 Step, by Radiohead), regardless of the order in which I try to play them. The audio just does not play, though the view loading and everything that happens concurrently happens correctly. The code is below. I get the "Player loaded." log output on the other two songs, but not on 15 Step. I know the file path is correct (I have it log outputted earlier in the app, and it is correct). Any ideas? NSData *musicData = [NSData dataWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:[song filename] ofType:nil]]]; NSLog([[NSBundle mainBundle] pathForResource:[song filename] ofType:nil]); if(musicData) { NSLog(@"File found."); } self.songView.player = [[AVAudioPlayer alloc] initWithData:musicData error:nil]; if(self.songView.player) { NSLog(@"Player loaded."); } [self.songView.player play]; NSLog(@"You should be hearing something now."); Thanks, Brendan

    Read the article

  • Asynchronous NSURLConnection Throws EXC_BAD_ACCESS

    - by Sheehan Alam
    I'm not really sure why my code is throwing a EXC_BAD_ACCESS, I have followed the guidelines in Apple's documentation: -(void)getMessages:(NSString*)stream{ NSString* myURL = [NSString stringWithFormat:@"http://www.someurl.com"]; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL]]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { receivedData = [[NSMutableData data] retain]; } else { NSLog(@"Connection Failed!"); } } And my delegate methods #pragma mark NSURLConnection Delegate Methods - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { // This method is called when the server has determined that it // has enough information to create the NSURLResponse. // It can be called multiple times, for example in the case of a // redirect, so each time we reset the data. // receivedData is an instance variable declared elsewhere. [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Append the new data to receivedData. // receivedData is an instance variable declared elsewhere. [receivedData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { // release the connection, and the data object [connection release]; // receivedData is declared as a method instance elsewhere [receivedData release]; // inform the user NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // do something with the data // receivedData is declared as a method instance elsewhere NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]); // release the connection, and the data object [connection release]; [receivedData release]; } I get an EXC_BAD_ACCESS on didReceiveData. Even if that method simply contains an NSLog, I get the error. Note: receivedData is an NSMutableData* in my header file

    Read the article

  • How does overlayViewTouched notification work in the MoviePlayer sample code

    - by Jonathan
    Hi, I have a question regarding the MoviePlayer sample code provided by apple. I don't understand how the overlayViewTouch notification works. The NSlog message I added to it does not get sent when I touch the view (not button). // post the "overlayViewTouch" notification and will send // the overlayViewTouches: message - (void)overlayViewTouches:(NSNotification *)notification { NSLog(@"overlay view touched"); // Handle touches to the overlay view (MyOverlayView) here... } I can, however, get the NSlog notification if I place it in -(void)touchesBegan in "MyOverlayView.m". Which makes me think it is recognizing touches but not sending a notification. // Handle any touches to the overlay view - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; if (touch.phase == UITouchPhaseBegan) { NSLog(@"overlay touched(from touchesBegan") // IMPORTANT: // Touches to the overlay view are being handled using // two different techniques as described here: // // 1. Touches to the overlay view (not in the button) // // On touches to the view we will post a notification // "overlayViewTouch". MyMovieViewController is registered // as an observer for this notification, and the // overlayViewTouches: method in MyMovieViewController // will be called. // // 2. Touches to the button // // Touches to the button in this same view will // trigger the MyMovieViewController overlayViewButtonPress: // action method instead. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName:OverlayViewTouchNotification object:nil]; } } Can anyone shed light on what I am missing or doing wrong? Thank you.

    Read the article

  • Objective-C: fetchManagedObjectsForEntity problem

    - by Meko
    Hi.I am trying to get value from CoreData entity name Person with predicate and then comparing with new data in dictionary.But it it returns every time 0 .And it creates about 5 person with same name. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userName == %@",[flickr usernameForUserID:@"owner"]]; peopleList = (NSMutableArray *)[flickr fetchManagedObjectsForEntity:@"Person" withPredicate:predicate]; NSEnumerator *enumerator = [peopleList objectEnumerator]; Person *person; BOOL exists = FALSE; while (person = [enumerator nextObject]) { NSLog(@" Person is: %@ ", person.userName); NSLog(@"Person ID IS %@",person.userID); NSLog(@"Dict ID is %@",[dict objectForKey:@"owner"]); if([person.userID isEqualToString:[dict objectForKey:@"owner"]]) { exists = TRUE; NSLog(@"-- Person Exists : %@--", person.userName); [newPhoto setPerson:person]; } } Here peopleList returns 0 and the enumerator also 0 and it does not use if and not comparing.In my entity I have Person and Photo entities.In Person I have userName and userID attributes and also one-to many relationship with Photo entity. I think problem in predicate but i cant figure out it .

    Read the article

  • Saving data - does work on Simulator, not on Device

    - by Peter Hajas
    I use NSData to persist an image in my application. I save the image like so (in my App Delegate): - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"Saving data"); NSData *data = UIImagePNGRepresentation([[viewController.myViewController myImage]image]); //Write the file out! NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path_to_file = [documentsDirectory stringByAppendingString:@"lastimage.png"]; [data writeToFile:path_to_file atomically:YES]; NSLog(@"Data saved."); } and then I load it back like so (in my view controller, under viewDidLoad): NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path_to_file = [documentsDirectory stringByAppendingString:@"lastimage.png"]; if([[NSFileManager defaultManager] fileExistsAtPath:path_to_file]) { NSLog(@"Found saved file, loading in image"); NSData *data = [NSData dataWithContentsOfFile:path_to_file]; UIImage *temp = [[UIImage alloc] initWithData:data]; myViewController.myImage.image = temp; NSLog(@"Finished loading in image"); } This code works every time on the simulator, but on the device, it can never seem to load back in the image. I'm pretty sure that it saves out, but I have no view of the filesystem. Am I doing something weird? Does the simulator have a different way to access its directories than the device? Thanks!

    Read the article

  • Two PickerViews in save View issue?

    - by NextRev
    I'm trying to have 2 pickerviews in the same view. It works except for two things. If one pickerview has more rows than the other the app crashes when picking an item from the pickerview with more items. Also I created an NSLog for the pickerviews and the console shows that I'm picking two items at once when in fact i'm only dealing with one pickerview. I know it sounds a bit confusing but I'm including all the code. Thank you in advance. list and list2 are NSMutableArrays list has 4 items list2 has 5 items There error: * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (4) beyond bounds (4)' -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView{ if([thePickerView isEqual:pickerView1 ]){ return 1; } else if([thePickerView isEqual:pickerView2]){ return 1; } else{ return 0; } } -(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component{ if([thePickerView isEqual:pickerView1 ]){ return [list count]; } else if([thePickerView isEqual:pickerView2]){ return [list2 count]; } else{ return 0; } } -(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ if([thePickerView isEqual:pickerView1 ]){ return [list objectAtIndex:row]; } else if([thePickerView isEqual:pickerView2]){ return [list2 objectAtIndex:row]; } else{ return 0; } } - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSLog(@"Selected item %@. Index of selected item:%i", [list objectAtIndex:row], row); NSLog(@"Selected item %@. Index of selected item:%i", [list2 objectAtIndex:row], row); NSLog(@"Selected item %@. Index of selected item:%i", [list3 objectAtIndex:row], row); if([thePickerView isEqual:pickerView1 ]){ //Do Something } else if([thePickerView isEqual:pickerView2 ]){ //Do Something } else if([thePickerView isEqual:pickerView3 ]){ //Do Something } }

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >