Search Results

Search found 28 results on 2 pages for 'nsmenu'.

Page 1/2 | 1 2  | Next Page >

  • NSMenu doesn't start tracking

    - by Measunny
    Hey, I have a little cocoa app which usually operates in the background (as agent). Sometimes I'd like to be able to popup a contextmenu (no window or s.th. visible at this time). As I'm only targetting Snow Leopard I tried this: if (windows) { NSMenu *theMenu = [[[NSMenu alloc] initWithTitle:@"test"] autorelease]; [theMenu setShowsStateColumn:NO]; [theMenu setAutoenablesItems:NO]; for (id item in windows) { NSString *labelText = @"some text"; NSMenuItem *theMenuItem = [[[NSMenuItem alloc] initWithTitle:labelText action:@selector(menuItemSelected:) keyEquivalent:@""] autorelease]; [theMenuItem setTarget:self]; [theMenuItem setRepresentedObject:item]; [theMenuItem setEnabled:YES]; [theMenuItem setImage:icon]; [theMenu addItem:theMenuItem]; } [theMenu popUpMenuPositioningItem:nil atLocation:[NSEvent mouseLocation] inView:nil]; } The menu popsup perfectly but if I hover the items with the mouse cursor they don't highlight and I can't click them. The menuItemSelected: method looks just like this: -(IBAction)menuItemSelected:(id)sender { } Any idea what I'm doing wrong?

    Read the article

  • Alternative Menu Items in NSMenu

    - by Nick Paulson
    Hi, I have an NSMenu that contains NSMenuItems with custom views. I want it so that when the alt button is pressed, the menu items would change part of their look (through their view). I found setAlternative in the NSMenuItem docs, however, in practice I could only get it to work with NSMenuItems without custom views. As soon as I set a custom view, all of the menu items would be displayed. Also, I tried getting keypress events while the menu was open. Due to the other run loop, NSApplication's sendEvent: doesn't receive events until after the menu is closed. Therefore, I can't just intercept the event coming in. Does anyone know how I can get notified, whether through delegation or subclassing, of when the alt key is pressed when a menu is opened?

    Read the article

  • How does Apple update the Airport menu while it is open? (How to change NSMenu when it is already op

    - by Tegeril
    I've got a statusbar item that pops open an NSMenu, and I have a delegate set and it's hooked up correctly (-(void)menuNeedsUpdate:(NSMenu *)menu works fine). That said, that method is setup to be called before the menu is displayed, I need to listen for that and trigger an asynchronous request, later updating the menu while it is open, and I can't figure out how that's supposed to be done. Thanks :)

    Read the article

  • How to add multiple menu items with the same title to NSPopUpButton(NSMenu)?

    - by William S. Pear
    As docs say it's impossible to add two menu items to NSPopUpButton if they both have the same title. I was trying to add menu items to [popupButton menu], but with no luck. I was also trying to create a new menu, add items to it and then use [popupButton setMenu:newMenu], but no. Menu always display only one item per name. But I know it should be possible, if you try to create a smart playlist in iTunes, you could select "Playlist" from the left popup button, "=" from the middle, and the right one will hold menu items for every playlist in iTunes EVEN if they have the same title. So how do they do it?

    Read the article

  • How to best share an NSMenu between multiple NSPopUpButton instances

    - by Frank R.
    Hi, I need to share the same NSMenu instance between multiple popup buttons. When I create an NSPopUpButton in IB, a new menu is automatically created and inserted as a child of the NSPopUpButtonCell. At the moment, I simply create an IBOutlet NSMenuItem* standardMenu member in my MainController and connect the "menu" outlets of the popup buttons to this, but this leaves the "fake" menus in the hierarchy. Surely, there's a clean way of doing this from inside IB? Thanks in advance for any advice you might be able to give.

    Read the article

  • Custom NSStatusItem with custom view - Use NSWindow, NSView, custom NSMenuItem?

    - by Luc
    I'm trying to create a LSUIElement app that behaves like Spotlight, CoverSutra and other apps of that type. I managed to create a custom NSStatusItem, which popups up an NSWindow but the problem is that the app that currently has focus will the focus to my custom NSWindow. I've based myself on Matt Gemmell's example (http://mattgemmell.com/2008/03/04/using-maattachedwindow-with-an-nsstatusitem) For example, if you're in Safari and click on the Spotlight icon, the current Safari window does not gray out and keeps focused. When you press ESC in Spotlight, the focus is back to the Safari window. I haven't managed to do this with my custom NSWindow. I have to click back on a window to set focus back to it. So I'd like to know which route to go to achieve this. Is the solution a NSWindow, NSPanel, NSMenu with a custom NSMenuItem?

    Read the article

  • Add a Contextual Menu to WebView

    - by Woodster
    An easy one, I think: I want to add a contextual menu to a WebView. In IB, I added a NSMenu to the NIB, connected it to the WebView's menu outlet, launched and expected to be able to control-click in the WebView and see the pop-up menu. The only item I saw on the contextual menu is "reload". I can do the same steps but connect the Menu to some other view and it works as expected. Why doesn't the menu work the same when connect to the webview's menu outlet? Thanks

    Read the article

  • How to add a pop-up menu to a NSToolbarItem?

    - by Rui Pacheco
    Hi, I'm trying to open a pop-up menu from a NSToolbarItem. I tried following this example but I can't use that class method because NSToolbar and NSToolbarItem inherit from NSObject and not from NSView. Apart from creating a custom view, what is the best way to open a pop-up menu from a NSToolbarItem?

    Read the article

  • Looking for popUpMenuPositioningItem:atLocation:inView: equivalent for 10.5

    - by Daniel Jette
    I'm working on an application that needs to display a context menu on screen in various scenarios. In the function I'm writing, I don't have access to any NSWindows or NSViews. I'd like to use popUpMenuPositioningItem:atLocation:inView as this function works perfectly for me in 10.6. However, we have a requirement to support 10.5, so this function isn't available to me. The feature I'm most interested in, as stated in the documentation is: If view is nil, the location is interpreted in the screen coordinate system. This allows you to pop up a menu disconnected from any window. Basically, I need to display the context menu given a location on screen, but without any associated view. Is there any way to achieve this on 10.5?

    Read the article

  • NSMenuItem not responding to setIndentationLevel:

    - by dave-gennel
    If I call setIndentationLevel: on an NSMenuItem then nothing happens, if I call indentationLevel on it to return its current level I get the default, 0. NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: @"title" action: nil keyEquivalent: @""]; [menuItem setIndentationLevel: 3]; [dockMenu addItem: menuItem];

    Read the article

  • Cocoa AppKit - Dismissing a modal window (i.e. popup or contextual menu) and pressing the button cu

    - by hishamk
    Basically I want to create the effect of that provided in the system's menu bar. A user presses on one of the menu headings, and as he moves across the different headings, the menus open up automatically. The snag is that if I open a pop-up menu for a button, the user has to click again to dismiss it. The entire runloop is on hold as I believe the pop-up menu is modal. How do I go about being able to send a [somePopUpMenu cancelTracking] when the user moves to the next button? Cheers

    Read the article

  • Usable mainmenu when sheet is shown

    - by neoneye
    How does one react to menuitems that are clicked via mouse or invoked via keyboard, e.g: CMD+Q ? [NSApp beginSheet:my_sheet ...arguments... ]; /* The sheet is now shown and the mainmenu isn't usable. How does one make it usable? */ [NSApp endSheet:my_sheet returnCode:0];

    Read the article

  • Conditionally disabling menu item

    - by Rui Pacheco
    Are menu items under File "special"? I've deleted Open Recent... from my application menu but it still shows up when I run the application. I've tried to clean all targets, I deleted other menu items to make sure there's no caching going on but I still can't make Open Recent... disappear at run time.

    Read the article

  • Mac OS X Status Bar Application - Hiding it from Cmd/Alt menu?

    - by Moddy
    I'm trying to whip up a simple little Status Bar Application in Obj-C/Cocoa. So I have done it pragmatically - declaring an NSStatusItem, adding it to the NSStatusBar and then giving it a NSMenu object. A bit like this... NSStatusBar *bar = [NSStatusBar systemStatusBar]; theItem = [bar statusItemWithLength:NSVariableStatusItemLength]; [theItem retain]; [theItem setTitle: NSLocalizedString(@"Tablet",@"")]; [theItem setHighlightMode:YES]; [theItem setMenu:theMenu]; (Example taken from "Status Bar Programming Topics", Apple Documentation) Now ideally, I'd like this application to run and not be accessible from the CMD/ALT window changing "menu" (for lack of a better word), I've seen applications do it before and would like that really. The idea is I just want it to be accessible from every window, whilst not having its own NSMenu on the status bar, and whilst not being able to have it as the active application ( - so its not able to take over the whole Status Bar, and its not able to be seen through CMD/ALT) Additionally, I was wondering if the StatusBarItem supports the ability to drag-n-drop an item onto it? I'm not sure if thats a limitation of the NSStatusBar though. I've read up on deamons and agents, but that seems far too low level/over kill for such a simplistic app! Cheers in advance!

    Read the article

  • Comparing against NSLocalizedString safe?

    - by George
    Hi, Sometimes I need to compare interface elements to other objects. At the moment I'm doing it by comparing their titles against a localized string. Am I right that I better compare my objects against IBOutlets? Tags are out of the question because I'm using NSMenu.

    Read the article

  • NSTableView and NSSearchField in an NSView, which is the outlet of an NSMenuItem, don't work

    - by Koning Baard XIV
    I'm having an NSView, which is set as the view: outlet of an NSMenuItem. The view contains an NSTableView (inside an NSScrollView) and an NSSearchField. The NSMenu is shown when the user clicks a specific NSStatusItem. When I launch the application from Xcode (Build and Run), the controls behave well, but whenever I launch it from the Finder (like the users would), they don't work and don't take any focus. My application is an LSUIElement. Can anyone help me out? Thanks.

    Read the article

  • NSStatusItem (cocoa) location on screen

    - by Craig
    I am trying to get the on screen location of an NSStatusItem so that I can perform a click on that area via code like below. I am doing this so that my users can press a hotkey to see the menu. event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, newLocation, kCGMouseButtonLeft); CGEventPost(kCGHIDEventTap, event); CFRelease(event); Does anyone know of a way to get the location?, I have been trying ideas and searching for days and have found several ideas but none of them seem to work in leopard/snow leopard The NSStatusItem is using an NSMenu not a custom view.

    Read the article

  • Which trick uses Apple to show icons in the dock contextual menu ?

    - by Matthieu Riegler
    My question is quite simple : To use a custom menu for the apps icon on the dock, - (NSMenu*) applicationDockMenu: (id) sender; of the NSApplicationDelegate has to return the menu that the dock will display. Using setImage on a NSMenuItem, you can normaly add icons to the menu. They show up on the normal menu, but not on in contextual menu of the app's dock icon. Then how did Apple manage QuickTime, XCode, Preview to show icons in the list of recent opened files accessible in their dock contextual menu ? Thx.

    Read the article

  • Cocoa Bindings and Application Preferences - Crash

    - by iaefai
    Using the document provided by Apple to create an application preferences window that doesn't require any extra code, I seem to have triggered a crash that cannot be traced by me. While the stuff from Apple is older, I believe I have the settings pretty much the same as shown here: When I run my application (Hcode) and go to the preferences menu item, it brings up the proper window with the defaults I specified in the bindings with the exception of the Spaces per tab is blank (no idea how to fix this). When the window is closed, the application crashes with a backtrace similar to this: (gdb) bt #0 0x00007fff800cb1d4 in objc_msgSend_vtable5 () #1 0x00007fff80447cf3 in -[NSMenu _enableItem:] () #2 0x00007fff80447ad8 in -[NSCarbonMenuImpl _carbonUpdateStatusEvent:handlerCallRef:] () #3 0x00007fff8042b3b0 in NSSLMMenuEventHandler () #4 0x00007fff80e06b57 in DispatchEventToHandlers () #5 0x00007fff80e060a6 in SendEventToEventTargetInternal () #6 0x00007fff80e23d85 in SendEventToEventTarget () #7 0x00007fff80e52e61 in SendHICommandEvent () #8 0x00007fff80e66357 in UpdateHICommandStatusWithCachedEvent () #9 0x00007fff80e02a6d in HIApplication::EventHandler () #10 0x00007fff80e06b57 in DispatchEventToHandlers () #11 0x00007fff80e060a6 in SendEventToEventTargetInternal () #12 0x00007fff80e23d85 in SendEventToEventTarget () #13 0x00007fff80e6599b in SendMenuOpening () #14 0x00007fff80e65388 in DrawTheMenu () #15 0x00007fff80e65149 in MenuChanged () #16 0x00007fff80e643d4 in TrackMenuCommon () #17 0x00007fff80e60dbe in MenuSelectCore () #18 0x00007fff80e60596 in _HandleMenuSelection2 () #19 0x00007fff802fc3b9 in _NSHandleCarbonMenuEvent () #20 0x00007fff802cfeda in _DPSNextEvent () #21 0x00007fff802cf379 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] () #22 0x00007fff8029505b in -[NSApplication run] () #23 0x00007fff8028dd7c in NSApplicationMain () #24 0x0000000100001cac in main (argc=1, argv=0x7fff5fbff5e0) at /Users/iaefai/Projects/Hcode/Source/main.m:13 I am at a complete loss as to what the problem is. Is there potentially a better way of doing this?

    Read the article

  • Dynamically populated NSPopUpButtonCell menu in an NSOutlineView

    - by Mo
    I’m working with an NSOutlineView which has two columns. My dataSource supplies the outline view with a tree of items of a custom class which represents file types (that is, you initialise it with a UTI). The first column is the display name of the file type (e.g., “Source code”, “Interface Builder NIB document”, etc.). The second column is an NSPopUpButtonCell which is supposed to allow the user to pick a handler for the given document type (think of Xcode’s “File Types” preference pane, and you’re pretty much there). I can generate an NSMenu for a given item in the tree, populated with options based upon the Launch Services database entries for the UTI, complete with the relevant application icon and and so on. In fact, the menu itself works wonderfully, populated by way of NSPopUpButtonCellWillPopUpNotification. The problem is, try as I might, the cell when the menu isn’t popped up always contains precisely one of two things: either an empty string, or the default text for the cell, the former if the result of -handlerName on the item (the attribute assigned to the column) is non-nil, the latter otherwise. Moreover, I’m manually calling -selectItem: on the NSPopUpButtonCell instance, which just seems Wrong. In contrast, the left-hand column, which is just an NSTextFieldCell, everything just works (although granted, all it’s got to do is read the value from the item and present it). (Disclaimer: I’m fairly new at Cocoa UI stuff; I know Objective-C, and lots of other programming languages, but I’ve not a huge amount of experience of building Mac OS X UIs, so be gentle).

    Read the article

  • Application crashing on getting updated information from database using timer and storing it on loca

    - by Amit Battan
    In our multi - user application we are continuously interacting with database. We have a common class through which we are sending POST queries to database and obtaining xml files in return. We are using delegates of NSXMLParser to parse the obtained file. The problem with us is we are facing many crashes in it generally when application is idle and changed data in database is being fetched in background through timer which is invoked after every few seconds. We have also dealt with error handling through try and catch but it proves to be of no use in this case and mostly application crashes with following error : Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000020 Strange thing is that many times the fetching of updated data at background works very fine, same methods being successfully executed under similar conditions but suddenly it crashes on one of them. The codes we are using is as follows: // we are using timer in this way: chkOnlineUser=[NSTimer scheduledTimerWithTimeInterval:15 target:mmObject selector:@selector(threadOnlineUser) userInfo:NULL repeats:YES]; // this method being called in timer -(void)threadOnlineUser{//HeartBeat in Thread [NSThread detachNewThreadSelector:@selector(onlineUserRefresh) toTarget:self withObject:nil]; } // this performs actual updation -(void)onlineUserRefresh{ NSAutoreleasePool *pool =[[NSAutoreleasePool alloc]init]; @try{ if(chkTimer==1){ return; } chkTimer=1; if([allUserArray count]==0){ [user parseXMLFileUser:@"all" andFlag:3]; [allUserArray removeAllObjects]; [allUserArray addObjectsFromArray:[user users]]; } [objHeartBeat parseXMLFile:[loginID intValue] timeOut:10]; NSMutableDictionary *tDictOL=[[NSMutableDictionary alloc] init]; tDictOL=[objHeartBeat onLineList]; NSArray *tArray=[[NSArray alloc] init]; tArray=[[tDictOL objectForKey:@"onlineuser"] componentsSeparatedByString:@","]; [loginUserArray removeAllObjects]; for(int l=0;l less than [tArray count] ;l++){ int t;//=[[tArray objectAtIndex:l] intValue]; if([[allUserArray valueForKey:@"Id"] containsObject:[tArray objectAtIndex:l]]){ t = [[allUserArray valueForKey:@"Id"] indexOfObject:[tArray objectAtIndex:l]]; [loginUserArray addObject:[allUserArray objectAtIndex:t]]; } } [onlineTable reloadData]; [logInUserPopUp removeAllItems]; if([loginUserArray count]==1){ [labelLoginUser setStringValue:@"Only you are online"]; [logInUserPopUp setEnabled:YES]; }else{ [labelLoginUser setStringValue:[NSString stringWithFormat:@" %d users online",[loginUserArray count]]]; [logInUserPopUp setEnabled:YES]; } NSMenu *menu = [[NSMenu alloc] initWithTitle:@"menu"]; NSMenuItem *itemOne = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; [menu addItem:itemOne]; for(int l=0;l less than [loginUserArray count];l++){ NSString *tempStr= [NSString stringWithFormat:@"%@ %@",[[[loginUserArray objectAtIndex:l] objectForKey:@"user_fname"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]],[[[loginUserArray objectAtIndex:l] objectForKey:@"user_lname"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; if(![tempStr isEqualToString:@""]){ NSMenuItem *itemOne = [[NSMenuItem alloc] initWithTitle:tempStr action:NULL keyEquivalent:@""]; [menu addItem:itemOne]; }else if(l==0){ NSMenuItem *itemOne = [[NSMenuItem alloc] initWithTitle:tempStr action:NULL keyEquivalent:@""]; [menu addItem:itemOne]; } } [logInUserPopUp setMenu:menu]; if([lastUpdateTime isEqualToString:@""]){ }else { [self fetchUpdatedInfo:lastUpdateTime]; [self fetchUpdatedGroup:lastUpdateTime];// function same as fetchUpdatedInfo [avObject fetchUpdatedInfo:lastUpdateTime];// function same as fetchUpdatedInfo [esTVObject fetchUpdatedInfo:lastUpdateTime];// function same as fetchUpdatedInfo } lastUpdateTime=[[tDictOL objectForKey:@"lastServerTime"] copy]; } @catch (NSException * e) { [queryByPost insertException:@"MainModule" inFun:@"onlineUserRefresh" excp:[e description] userId:[loginID intValue]]; NSRunAlertPanel(@"Error Panel", @"Main Module- onlineUserRefresh....%@", @"OK", nil, nil,e); } @finally { NSLog(@"Internal Update Before Bye"); chkTimer=0; NSLog(@"Internal Update Bye");// Some time application crashes after this log // Some time application crahses after "Internal Update Bye" log } } // The method which we are using to obtain updated data is of following form: -(void)fetchUpdatedInfo:(NSString *)UpdTime{ @try { if(initAfterLoginComplete==0){ return; } [user parseXMLFileUser:UpdTime andFlag:[loginID intValue]]; [tempUserUpdatedArray removeAllObjects]; [tempUserUpdatedArray addObjectsFromArray:[user users]]; if([tempUserUpdatedArray count]0){ if([contactsView isHidden]){ [topContactImg setImage:[NSImage imageNamed:@"btn_contacts_off_red.png"]]; }else { [topContactImg setImage:[NSImage imageNamed:@"btn_contacts_red.png"]]; } }else { return; } int chkprof=0; for(int l=0;l less than [tempUserUpdatedArray count];l++){ NSArray *tempArr1 = [allUserArray valueForKey:@"Id"]; int s; if([[[tempUserUpdatedArray objectAtIndex:l] objectForKey:@"Id"] intValue]==profile_Id){ chkprof=1; } if([tempArr1 containsObject:[[tempUserUpdatedArray objectAtIndex:l] objectForKey:@"Id"]]){ s = [tempArr1 indexOfObject:[[tempUserUpdatedArray objectAtIndex:l] objectForKey:@"Id"]]; [allUserArray replaceObjectAtIndex:s withObject:[tempUserUpdatedArray objectAtIndex:l]]; }else { [allUserArray addObject:[tempUserUpdatedArray objectAtIndex:l]]; } NSArray *tempArr2 = [tempUser valueForKey:@"Id"]; if([tempArr2 containsObject:[[tempUserUpdatedArray objectAtIndex:l] objectForKey:@"Id"]]){ s = [tempArr2 indexOfObject:[[tempUserUpdatedArray objectAtIndex:l] objectForKey:@"Id"]]; [tempUser replaceObjectAtIndex:s withObject:[tempUserUpdatedArray objectAtIndex:l]]; }else { [tempUser addObject:[tempUserUpdatedArray objectAtIndex:l]]; } } NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"user_fname" ascending:YES]; [tempUser sortUsingDescriptors:[NSMutableArray arrayWithObject:sortDescriptor]]; [userListTableView reloadData]; [groupsArray removeAllObjects]; for(int z=0;z less than [tempGroups count];z++){ NSMutableArray *tempMArr=[[NSMutableArray alloc] init]; for(int l=0;l less than [allUserArray count];l++){ if([[[allUserArray objectAtIndex:l] objectForKey:@"GroupId"] intValue]==[[[tempGroups objectAtIndex:z] objectForKey:@"group_id"] intValue]){ [tempMArr addObject:[allUserArray objectAtIndex:l]]; } } [groupsArray insertObject:tempMArr atIndex:z]; [tempMArr release]; tempMArr= nil; } for(int n=0;n less than [tempGroups count];n++){ [[groupsArray objectAtIndex:n] addObject:[tempGroups objectAtIndex:n]]; } [groupsListOV reloadData]; if(chkprof==1){ [self profileShow:profile_Id]; }else { } [self selectUserInTable:0]; }@catch (NSException * e) { NSRunAlertPanel(@"Error Panel", @"%@", @"OK", nil, nil,e); } } // The method which we are using to frame select query and parse obtained data is: -(void)parseXMLForUser:(int)UId stringVar:(NSString*)stringVar{ @try{ if(queryByPost) [queryByPost release]; queryByPost=[QueryByPost new]; // common class used to invoke method to send request via POST method //obtaining data for xml parsing NSString *query=[NSString stringWithFormat:@"Select * from userinfo update_time = '%@' AND NOT owner_id ='%d' ",stringVar,UId]; NSData *obtainedData=[queryByPost executeQuery:query WithAction:@"query"]; // method invoked to perform post query if(obtainedData==nil){ // data not obtained so return return; } // initializing dictionary to be obtained after parsing if(obtainedDictionary) [obtainedDictionary release]; obtainedDictionary=[NSMutableDictionary new]; // xml parsing if (updatedDataParser) // airportsListParser is an NSXMLParser instance variable [updatedDataParser release]; updatedDataParser = [[NSXMLParser alloc] initWithData:obtainedData]; [updatedDataParser setDelegate:self]; [updatedDataParser setShouldResolveExternalEntities:YES]; BOOL success = [updatedDataParser parse]; } @catch (NSException *e) { NSLog(@"wtihin parseXMLForUser- parseXMLForUser:stringVar: - %@",[e description]); } } //The method which will attempt to interact 4 times with server if interaction with it is found to be unsuccessful , is of following form: -(NSData*)executeQuery:(NSString*)query WithAction:(NSString*)doAction{ NSLog(@"within ExecuteQuery:WithAction: Query is: %@ and Action is: %@",query,doAction); NSString *returnResult; @try { NSString *returnResult; NSMutableURLRequest *postRequest; NSError *error; NSData *searchData; NSHTTPURLResponse *response; postRequest=[self directMySQLQuery:query WithAction:doAction]; // this method sends actual POST request NSLog(@"after directMYSQL in QueryByPost- performQuery... ErrorLogMsg"); searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error]; returnResult = [[NSString alloc] initWithData:searchData encoding:NSASCIIStringEncoding]; NSString *resultToBeCompared=[returnResult stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSLog(@"result obtained - %@/ resultToBeCompared - %@",returnResult,resultToBeCompared); if(![resultToBeCompared isEqualToString:@""]){ }else { sleep(10); postRequest=[self directMySQLQuery:query WithAction:doAction]; searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error]; if(![resultToBeCompared isEqualToString:@""]){ }else { sleep(10); postRequest=[self directMySQLQuery:query WithAction:doAction]; searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error]; if(![resultToBeCompared isEqualToString:@""]){ }else { sleep(10); postRequest=[self directMySQLQuery:query WithAction:doAction]; searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error]; if(![resultToBeCompared isEqualToString:@""]){ }else { sleep(10); postRequest=[self directMySQLQuery:query WithAction:doAction]; searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error]; if(![resultToBeCompared isEqualToString:@""]){ }else { return nil; } } } } } returnResult = [[NSString alloc] initWithData:searchData encoding:NSASCIIStringEncoding]; return searchData; } @catch (NSException * e) { NSLog(@"within QueryByPost , execurteQuery:WithAction - %@",[e description]); return nil; } } // The method which sends POST request to server , is of following form: -(NSMutableURLRequest *)directMySQLQuery:(NSString*)query WithAction:(NSString*)doAction{ @try{ NSLog(@"Query is: %@ and Action is: %@",query,doAction); // some pre initialization NSString *stringBoundary,*contentType; NSURL *cgiUrl ; NSMutableURLRequest *postRequest; NSMutableData *postBody; NSString *ans=@"434"; cgiUrl = [NSURL URLWithString:@"http://keysoftwareservices.com/API.php"]; postRequest = [NSMutableURLRequest requestWithURL:cgiUrl]; [postRequest setHTTPMethod:@"POST"]; stringBoundary = [NSString stringWithString:@"0000ABCQueryxxxxxx"]; contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", stringBoundary]; [postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"]; //setting up the body: postBody = [NSMutableData data]; [postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"code\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:ans] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"action\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:doAction] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"devmode\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"devmode"]] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"q\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:query] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postRequest setHTTPBody:postBody]; NSLog(@"Direct My SQL ok");// Some time application crashes afte this log //Some time application crashes after "Direct My SQL ok" log return [postRequest mutableCopy]; }@catch (NSException * e) { NSLog(@"NSException %@",e); NSRunAlertPanel(@"Error Panel", @"Within QueryByPost- directMySQLQuery...%@", @"OK", nil, nil,e); return nil; } }

    Read the article

1 2  | Next Page >