Search Results

Search found 2691 results on 108 pages for 'ios'.

Page 14/108 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • iOS - Application logging test and production code

    - by Peter Warbo
    I am doing a bunch of logging when I'm testing my application which is useful for getting information about variable state and such. However I have read that you should use logging sparsely in production code (because it can potentially slow down your application). But my question is now: if my app is in production and people are using it, whenever a crash (god forbid) occurs, how will I be able to interpret the crash information if I have removed the logging statements? Then I suppose I will only have a stacktrace for me to interpret? Does this mean I should leave logging in production code only WHERE it's really essential for me to interpret what has happened? Also how will the logging statements relate to the crash reports? Will they be combined? I'm thinking of using Flurry as analytics and crash reports...

    Read the article

  • AFNetworking iOS

    - by Jeromiin
    I have a problem with a request in my app, I want to receive a json but because of the completion block my "PRINT 2" is print before my "PRINT 1" and of course my "PRINT 2" is null. I want the contrary and my "PRINT 2" to be filled but I can't manage to do it. -(void) makeConnection { NSURL *url = [NSURL URLWithString:[@"http://monsite.com/iPhonej/verifPseudo.php?login="stringByAppendingString:[_loginField.text stringByAppendingString:[@"&password=" stringByAppendingString:_passField.text]]]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { self.response = (NSDictionary *)responseObject; NSLog(@"PRINT 1 : %@", self.response[@"la"][@"reponse"][0][@"rep"]); [_dataLock lock]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Request Failed: %@, %@", error, error.userInfo); }]; [operation start]; } - (IBAction)logIn:(id)sender { [self makeConnection]; NSLog(@"PRINT 2 : %@", self.response[@"la"][@"reponse"][0][@"rep"]); } I know that AFNetworking is asynchronous but is there an other way to do the request and receive my json well ? Thank you

    Read the article

  • Can't figure out this file behavior in IOS 4.2

    - by Don Jones
    Odd behavior with file behavior. Here's the thing: I'm using the phone camera to snap a picture, and internally generating a thumbnail. I'm saving those as temp files in the Documents directory. Here's the complete code: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; photo = [self scaleAndRotateImage:photo]; // save photo NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSLog(@"Writing to %@",docsDir); // save photo file NSLog(@"Saving photo as %@",[NSString stringWithFormat:@"%@/temp_photo.png",docsDir]); [UIImagePNGRepresentation(photo) writeToFile:[NSString stringWithFormat:@"%@/temp_photo.png",docsDir] atomically:YES]; // make and save thumbnail NSLog(@"Saving thumbnail as %@",[NSString stringWithFormat:@"%@/temp_thumb.png",docsDir]); UIImage *thumb = [self makeThumbnail:photo]; [UIImagePNGRepresentation(thumb) writeToFile:[NSString stringWithFormat:@"%@/temp_thumb.png",docsDir] atomically:YES]; NSFileManager *manager = [NSFileManager defaultManager]; NSError *error; NSArray *files = [manager contentsOfDirectoryAtPath:docsDir error:&error]; NSLog(@"\n\nThere are %d files in the documents directory %@",(files.count),docsDir); for (int i = 0; i < files.count; i++) { NSString *filename = [files objectAtIndex:i]; NSLog(@"Seeing filename %@",filename); } // done //[photo release]; //[thumb release]; [self dismissModalViewControllerAnimated:NO]; [delegate textInputFinished]; } As you can see, I've put quite a bit of logging in here in an attempt to figure out my problem (which is coming up). The log output to this point is: Writing to /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents Saving photo as /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents/temp_photo.png Saving thumbnail as /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents/temp_thumb.png There are 3 files in the documents directory /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents Seeing filename temp_photo.png Seeing filename temp_text.txt Seeing filename temp_thumb.png This is absolutely as-expected. I clearly have three files on the device. Here's the very next code that operates - the code that received the textInputFinished message: - (void)textInputFinished { NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSError *error; // get next filename NSString *filename; int i = 0; do { i++; filename = [NSString stringWithFormat:@"%@/reminder_%d",docsDir,i]; NSLog(@"Trying filename %@",filename); } while ([fileManager fileExistsAtPath:[filename stringByAppendingString:@".txt"]]); NSLog(@"New base filename is %@",filename); NSArray *files = [fileManager contentsOfDirectoryAtPath:docsDir error:&error]; NSLog(@"There are %d files in the directory %@",(files.count),docsDir); This is testing to get a new, non-temp, not-in-use filename. It does that - but then it says there aren't any files in the documents folder! Here's the logged output: Trying filename /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents/reminder_1 New base filename is /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents/reminder_1 There are 0 files in the directory /var/mobile/Applications/77D792DC-A224-4A47-8A4C-BB7C557626F3/Documents What the heck? Where did the three files go?

    Read the article

  • ios - UISegmentedControl and NSString

    - by Jeff Kranenburg
    Hello I have the following code: if(_deviceSegmentCntrl.selectedSegmentIndex == 0) { deviceOne = [[NSString alloc] initWithFormat:@"string01"]; } if(_deviceSegmentCntrl.selectedSegmentIndex == 1) { deviceOne = [[NSString alloc] initWithFormat:@"string02"]; } if(_deviceSegmentCntrl.selectedSegmentIndex == 2) { deviceOne = [[NSString alloc] initWithFormat:@"string03"]; } NSString *deviceType = [[NSString alloc] initWithFormat:_deviceSegmentCntrl]; I am wanting to have the NSString output the string the user selects in the segmented control. How do I append the initWithFormat: so that it reflects the chosen index? Cheers

    Read the article

  • Json get a parameter can't access on it iOS

    - by Usi Usi
    That's an example { "updated":1350213484, "id":"http://www.google.com/reader/api/0/feed-finder?q\u003dProva\u0026output\u003djson", "title":"Risultati di feed per \"Prova\"", "self":[ { "href":"http://www.google.com/reader/api/0/feed-finder?q\u003dProva\u0026output\u003djson" } ], "items":[ { "title":"Home Page - La prova del cuoco", "id":"http://www.laprovadelcuoco.rai.it/", "updated":1350213485, "feed":[ { "href":"http://www.laprovadelcuoco.rai.it/dl/portali/site/page/Page-ffb545b4-9e72-41e5-866f-a465588c43fa-rss.html" } ], "alternate":[ { "href":"http://www.laprovadelcuoco.rai.it/", "type":"text/html" } ], "content":{ "direction":"ltr", "content":"Diventa un cuoco provetto con “La Prova del Cuoco”: le videoricette in un' applicazione di facile e veloce consultazione per il tuo Iphone. Scopri come acquistare ..." } }, { "title":"Le prove Invalsi di matematica e italiano", "id":"http://online.scuola.zanichelli.it/quartaprova/", "updated":1350213486, "feed":[ { "href":"http://online.scuola.zanichelli.it/quartaprova/feed/" } ], "alternate":[ { "href":"http://online.scuola.zanichelli.it/quartaprova/", "type":"text/html" } ], "content":{ "direction":"ltr", "content":"Un sito Zanichelli dedicato alle prove Invalsi di italiano e matematica: esercitazioni, consigli, informazioni utili, novità, aggiornamenti e blog d'autore sulle prove ..." } }, How can I get the feed URL? That's what I do NSString *daParsare=[reader searchFeed:searchText]; NSArray *items = [[daParsare JSONValue] objectForKey:@"items"]; for (NSDictionary *item in items) { NSString *title = [item objectForKey:@"title"]; NSString *feed = [item valueForKeyPath:@"feed.href"]; } [tab reloadData]; With the title everything is ok but when I try to access to the feed paramater I get the error...

    Read the article

  • iOS iPad Master Detail template can't interact with detail view

    - by CraigularB
    I have an iPad app generated from the Master-Detail template in XCode. The iPad Storyboard has under the Detail View Controller a View that holds a ScrollView which holds an ImageView. In the DetailViewController.m file I added the following code to allow the ScrollView to move and zoom the image: -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.comicImage; } This works great on the iPhone (it's a universal app) but not the iPad; I can scroll and zoom the image on the iPhone no problem, but on the iPad it's like the ScrollView isn't responding to the touches, and I can't figure out how to pass the touches on to the ScrollView. I've already deactivated the popover controller from appearing with a right swipe like this: self.splitViewController.presentsWithGesture = NO; How do I make it so the user can interact with the ScrollView in the DetailViewController?

    Read the article

  • ios how can user cancel facebook sign in?

    - by Jackson
    When a user gets to this screen, there is no way to cancel out of it. What can I do? To get this view in the first place I am running: NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: vid, @"link", vid, @"source", vid, @"picture", @"My Place", @"name", @"YouTube Presentation", @"caption", title, @"description", @"Enjoy this Video", @"message", nil]; [app.facebook dialog:@"stream.publish" andParams:params andDelegate:self];

    Read the article

  • Memory management in iOS

    - by angrest
    Looks like I did not understand memory management in Objective C... sigh. I have the following code (note that in my case, placemark.thoroughfare and placemark.subThoroughfare are both filled with valid data, thus both if-conditions will be TRUE if (placemark.thoroughfare) { [item.place release]; item.place = [NSString stringWithFormat:@"%@ ", placemark.thoroughfare]; } else { [item.place release]; item.place = @"Unknown Place"; } if (placemark.thoroughfare && placemark.subThoroughfare) { // *** problem is here *** [item.place release]; item.place = [NSString stringWithFormat:@"%@ %@", placemark.thoroughfare , placemark.subThoroughfare]; } If I do not release item.place at the marked location in the code, Instruments finds a memory leak there. If I do, the program crashes as soon as I try to access item.place outside the offending method. Any ideas?

    Read the article

  • Data files from development machine to iOS device

    - by StoneBreaker
    My app has created a bunch of data files as development has progressed through the simulator. Their location is obtained by this function: NSString *pathInDocumentDirectory(NSString *fileName) { NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [documentDirectories objectAtIndex: 0]; return [documentDirectory stringByAppendingPathComponent: fileName]; } The files are now required on the device as testing of the app is moving from the simulator to actual devices. How do I transfer the data files from my current working environment to the devices?

    Read the article

  • Parsing json in ios

    - by gaps
    i have the follwing json string ,can anybody tell me how to get the value of role_name {"response":"success","user":{"created_at":"2011-11-16T05:48:31Z","ud_id":"1234567890","last_sign_in_ip":"182.72.141.194","updated_at":"2011-11-19T08:58:27Z","account_id":21,"last_name":"dfg","role_name":"Parent","email":"[email protected]","first_name":"abc"},"status":"200"} code for parsing is NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"resp--- %@",responseString); NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"user"]; NSDictionary* loan = [latestLoans objectAtIndex:0]; NSString* name = [loan objectForKey:@"last_name"];

    Read the article

  • How to play audio file ios

    - by Camus
    I am trying to play an audio file but I can get it working. I imported the AVFoundation framework. Here is the code: NSString *fileName = [[NSBundle mainBundle] pathForResource:@"Alarm" ofType:@"caf"]; NSURL *url = [[NSURL alloc] initFileURLWithPath:fileName]; NSLog(@"Test: %@ ", url); AVAudioPlayer *audioFile = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; audioFile.delegate = self; audioFile.volume = 1; [audioFile play]; I am receiving an error nil string parameter I copied the file to the supporting files folder so the file is there. Can you guys help me? Thanks

    Read the article

  • iOS UIImageView dataWithContentsOfURL returning empty

    - by user761389
    I'm trying to display an image from a URL in a UIImageView and I'm seeing some very peculiar results. The bit of code that I'm testing with is below imageURL = @"http://images.shopow.co.uk/image/user_dyn/1073/32/32"; imageURL = @"http://images.shopow.co.uk/assets/profile_images/default/32_32/avatar-male-01.jpg"; NSURL *imageURLRes = [NSURL URLWithString:imageURL]; NSData *imageData = [NSData dataWithContentsOfURL:imageURLRes]; UIImage *image = [UIImage imageWithData:imageData]; NSLog(@"Image Data: %@", imageData); In it's current form I can see data in the output window which is what I'd expect. However if comment out the second imageURL so I'm referencing the first I'm getting empty data and therefore nil is being returned by imageWithData. What is possibly more confusing is that the first image is basically the same as the second but it's been through a PHP processing script. I'm nearly certain that it isn't the script that's causing the issue because if I use this instead imageURL = @"http://images.shopow.co.uk/image/product_dynimg/389620/32/32" the image is displayed and this uses the same image processing script. I'm struggling to find any difference in the images that would cause this to occur. Any help would be appreciated.

    Read the article

  • Set text equal to string and pass to receipt printer at a different size on iOS

    - by Max Roper
    I am using the StarIO SDK to print text to a receipt printer and I am trying to get a certain line of text larger than the rest. I have some help from their support but I can't really get it to go. -(void)print{ NSMutableString *final=[NSMutableString stringWithFormat:@"-----"]; [final appendFormat:@"\n\nLevel:%@ Section:%@ Row:%@ Seat:%@", [response_dict objectForKey:@"level"], [response_dict objectForKey:@"section"],[response_dict objectForKey:@"row"],[response_dict objectForKey:@"seat"]]; There is a bunch of other stuff that is printing, but that is the line that I would like to be a different size than the rest. The StarIO support said that I should try and pass that to this... -(IBAction)PrintText { NSString *portName = [IOS_SDKViewController getPortName]; NSString *portSettings = [IOS_SDKViewController getPortSettings]; [PrinterFunctions PrintTextWithPortname:portName portSettings:portSettings heightExpansion:heightExpansion widthExpansion:widthExpansion textData:textData textDataSize:[textNSData length]]; free(textData); } Would love some help if possible. :) Thanks so much. This is the main bit I think I would need from the StarIO Text formatting doc... - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { array_hieghtExpansion = [[NSMutableArray alloc] init]; [array_hieghtExpansion addObject:@"1"]; [array_hieghtExpansion addObject:@"2"]; [array_hieghtExpansion addObject:@"3"]; [array_hieghtExpansion addObject:@"4"]; [array_hieghtExpansion addObject:@"5"]; [array_hieghtExpansion addObject:@"6"]; array_widthExpansion = [[NSMutableArray alloc] init]; [array_widthExpansion addObject:@"1"]; [array_widthExpansion addObject:@"2"]; [array_widthExpansion addObject:@"3"]; [array_widthExpansion addObject:@"4"]; [array_widthExpansion addObject:@"5"]; [array_widthExpansion addObject:@"6"]; array_alignment = [[NSMutableArray alloc] init]; [array_alignment addObject:@"Left"]; [array_alignment addObject:@"Center"]; [array_alignment addObject:@"Right"]; } return self; } and int heightExpansion = [pickerpopup_heightExpansion getSelectedIndex]; int widthExpansion = [pickerpopup_widthExpansion getSelectedIndex];

    Read the article

  • Find out number of fraction digits in currency in iOS

    - by thejaz
    I use NSNumberFormatter to format currencies in a localized way, and it works fine. But I want to override this and give the user the option to override the number of digits after the decimal separator. How can I find out the number of digits the NSNumberFormatter will use for a certain currency? I have looked in the NSLocale object, but none of the keys tell me this. NSString * const NSLocaleIdentifier; NSString * const NSLocaleLanguageCode; NSString * const NSLocaleCountryCode; NSString * const NSLocaleScriptCode; NSString * const NSLocaleVariantCode; NSString * const NSLocaleExemplarCharacterSet; NSString * const NSLocaleCalendar; NSString * const NSLocaleCollationIdentifier; NSString * const NSLocaleUsesMetricSystem; NSString * const NSLocaleMeasurementSystem; NSString * const NSLocaleDecimalSeparator; NSString * const NSLocaleGroupingSeparator; NSString * const NSLocaleCurrencySymbol; NSString * const NSLocaleCurrencyCode; NSString * const NSLocaleCollatorIdentifier; NSString * const NSLocaleQuotationBeginDelimiterKey; NSString * const NSLocaleQuotationEndDelimiterKey; NSString * const NSLocaleAlternateQuotationBeginDelimiterKey; NSString * const NSLocaleAlternateQuotationEndDelimiterKey; How can I find out the correct number of decimals for a currency like the NSNumberFormatter seems to know?

    Read the article

  • Timezoneoffset error when daylightsaving in effect in iOS

    - by Ranjit
    friends,I am getting a date based on the calculation I have done below NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *expectedDate = [gregorian dateByAddingComponents:components toDate:startDate options:0]; NSTimeInterval timeZoneOffset = -[[NSTimeZone systemTimeZone] secondsFromGMTForDate:expectedDate]; NSDate *localDate = [expectedDate dateByAddingTimeInterval:(timeZoneOffset)]; NSString *date = [dateFormatter stringFromDate:localDate]; But the date goes wrong when the daylightsaving is in effect,and also the timeZoneOffset changes when the daylightsaving is in effect, but I want the same date irrespective of whether the daylight saving is in effect or no.. So friends,how shall I handle this situation,please help. Regards Ranjit

    Read the article

  • iOS - Open certain view controller with URL scheme

    - by hansenmd
    I'm playing around with URL schemes in my app. I easily made one to open my app, just adding the necessary items to info.plist. This current URL "myappname://" takes the user to the initial view controller, FirstTableViewController, but I was wondering if it would be possible to modify that URL scheme so it I can have one that takes the user to a certain view controller, such as ThirdTableViewController. I would use this as a handy feature in something like Launch Center.

    Read the article

  • iOS get user contacts excluding businesses

    - by Kyle Begeman
    I have an app that is loading all of a users contacts. I would like to exclude any business, but I can't seem to find a way to determine if a contact is a business. I initially considered check if the "company" field contains a value when the first and last name do not, but I can't find this property from the ABRecord. Here is how I am grabbing the first and last name: NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty); NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty); Any ideas? Thanks!

    Read the article

  • Memory Management iOS dev app doesn't work after a few detail items

    - by user1434846
    I am working on a project with a tableView controller and the detail views contains CMMotionManager.When i open 5 or 6 detailViews all goes well,but after a while the app goes slow and finally crashes.On instruments the only leak is on main.m , also i must say that I'm using ARC and i can't dealloc or realese the instances. Here is the code: First the table view: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.title = @"Movement";//Master View Controller title bar UIImage *image = [UIImage imageNamed:@"jg_navibar.png"]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; //Init the array with data bodypartsMutableArray = [NSMutableArray arrayWithCapacity:26]; BodypartData *part1 = [[BodypartData alloc] init]; part1.bodypartname = @"Shoulder"; part1.movementname = @"Flexion"; part1.fullimageStartingPosition=[UIImage imageNamed:@"2_shoulder_flexion_end_position.jpg"]; part1.fullimageEndedPosition=[UIImage imageNamed:@"2_shoulder_flexion_end_position.jpg"]; part1.thumbimage=[UIImage imageNamed:@"1_shoulder_flexion_landmarks_thumb.jpg"]; [bodypartsMutableArray addObject:part1]; ......... } then the cell: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyBasicCell"]; BodypartData *part = [self.bodypartsMutableArray objectAtIndex:indexPath.row]; cell.textLabel.text =[NSString stringWithFormat:part.movementname]; cell.detailTextLabel.text =[NSString stringWithFormat:part.bodypartname]; cell.imageView.image =part.thumbimage; return cell; } and the the detailViewdid load: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Init motionManager object and set the Update Interval _motionManager = [[CMMotionManager alloc]init]; _motionManager.deviceMotionUpdateInterval=1/60; //60 Hz [_motionManager startGyroUpdates]; if (_motionManager.gyroAvailable) { _motionManager.gyroUpdateInterval = 1.0/60.0; [_motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler: ^(CMDeviceMotion *motion, NSError *error) { CMAttitude *attitude = motion.attitude; //Calculation with rotationMatrix m11 = [NSString stringWithFormat:@"%.02f", attitude.rotationMatrix.m11]; m12 = [NSString stringWithFormat:@"%.02f", attitude.rotationMatrix.m12]; m13 = [NSString stringWithFormat:@"%.02f", attitude.rotationMatrix.m13]; ......... }

    Read the article

  • Regular non-low energy bluetooth for IOS

    - by user3712524
    Ok, so I can't get my app to connect with a peripheral using bluetooth low-energy(my app is installed on an iPhone 5s and I have LightBlue installed on an iPhone 4S, simulating a peripheral. I also have light blue installed on the 5s, simulating a central, to verify that the two can connect and they do.) I have verified that the centralManager is instantiating and the State is powered on. So, my question is, is regular bluetooth still a viable option? Can I just use the GameKit API and go that route? Thanks in advance!

    Read the article

  • How to flush coverage data when my test cause app crash - For ios app

    - by Ypy
    I want to get the code coverage of my tests. So I set the settings, build an app with .gcno files and run it on simulator. It can get the coverage data successfully if there is no crash issue. But if the app crashed, I will get nothing. So how can I get the code coverage data when the app crash? In my thought, this is because it will not call __gcov_flush() method when app crash. I only add app does not run in background to my plist file, so __gcov_flush() is called only at the time I press Home button. Is there any way to call __gcov_flush() before the app crash?

    Read the article

  • iOS subview widget hooked up to multiple controllers

    - by Allison A
    So, I want to create a reusable widget as a xib and subview that can appear on a set amount of specific screens. This widget will have three buttons, each with an Action. I want to be able to handle these actions on multiple viewcontrollers. So say ViewControllerA, ViewControllerD, and ViewControllerF can handle the three button events, each in their own way. I've created the nib file. How do I import it into the specific viewcontrollers, and then how do I wire up those events? EDIT: I know that I could potentially get outlets set up via a viewcontroller, but Apple states that UIViewController is for full-screen views only, and my widget is only taking up a small portion of the screen.

    Read the article

  • iOS - is it possible to cache CGContextDrawImage?

    - by woot586
    I used the timing profile tool to identify that 95% of the time is spent calling the function CGContextDrawImage. In my app there are a lot of duplicate images repeatably being chopped from a sprite map and drawn to the screen. I was wondering if it was possible to cache the output of CGContextDrawImage in an NSMutableDictionay, then if the same sprite is requested again it can be just pull it from the cache rather than doing all the work of clipping and rendering it again. This is what i’ve got but I have not been to successful: Definitions if(cache == NULL) cache = [[NSMutableDictionary alloc]init]; //Identifier based on the name of the sprite and location within the sprite. NSString* identifier = [NSString stringWithFormat:@"%@-%d",filename,frame]; Adding to cache CGRect clippedRect = CGRectMake(0, 0, clipRect.size.width, clipRect.size.height); CGContextClipToRect( context, clippedRect); //create a rect equivalent to the full size of the image //offset the rect by the X and Y we want to start the crop //from in order to cut off anything before them CGRect drawRect = CGRectMake(clipRect.origin.x * -1, clipRect.origin.y * -1, atlas.size.width, atlas.size.height); //draw the image to our clipped context using our offset rect CGContextDrawImage(context, drawRect, atlas.CGImage); [cache setValue:UIGraphicsGetImageFromCurrentImageContext() forKey:identifier]; UIGraphicsEndImageContext(); Rendering a cached sprite There is probably a better way to render CGImage which is my ultimate caching goal but at the moment I’m just looking to successfully render the cached image out however this has not been successful. UIImage* cachedImage = [cache objectForKey:identifier]; if(cachedImage){ NSLog(@"Cached %@",identifier); CGRect imageRect = CGRectMake(0, 0, cachedImage.size.width, cachedImage.size.height); if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0); else UIGraphicsBeginImageContext(imageRect.size); //Use draw for now just to see if the image renders out ok CGContextDrawImage(context, imageRect, cachedImage.CGImage); UIGraphicsEndImageContext(); }

    Read the article

  • Format textfield while typing Ios

    - by BBios
    Ive seen other examples and tried - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string I am not sure what I am doing wrong, I just started coding my first Iphone App This is what I am trying to do I have 4 textfields and each has a limit on number of letters while typing I have done this using the below code - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { int valid; NSString *cs2 = [textField.text stringByReplacingCharactersInRange:range withString:string]; // int charCount = [cs2 length]; if(textField == cvv){ valid = 4; }else if(textField == cardName) { valid=26; }else if(textField == expDate) { valid=5; // if (charCount == 2 ) { // textField.text = [cs2 stringByAppendingString:@"/"]; // textField.text = cs2; // return YES; // } }else if(textField == acNumber) { valid=19; } return !([cs2 length] > valid); Works fine till here, I have a textfield where the user enters Exp date and would like to format it as if I am entering 112 then it should display as 01/12 and if I enter 2 then it should display as 1122 I tried checking if the length of the textfield value is 2 then append a / but then that gives me when I enter 12 it gives 11/22

    Read the article

  • iOs receivedData from NSURLConnection is nil

    - by yhl
    I was wondering if anyone could point out why I'm not able to capture a web reply. My NSLog shows that my [NSMutableData receivedData] has a length of 0 the entire run of the connection. The script that I hit when I click my login button returns a string. My NSLog result is pasted below, and after that I've pasted both the .h and .m files that I have. NSLog Result 2012-11-28 23:35:22.083 [12548:c07] Clicked on button_login 2012-11-28 23:35:22.090 [12548:c07] theConnection is succesful 2012-11-28 23:35:22.289 [12548:c07] didReceiveResponse 2012-11-28 23:35:22.290 [12548:c07] didReceiveData 2012-11-28 23:35:22.290 [12548:c07] 0 2012-11-28 23:35:22.290 [12548:c07] connectionDidFinishLoading 2012-11-28 23:35:22.290 [12548:c07] 0 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController // Create an Action for the button. - (IBAction)button_login:(id)sender; // Add property declaration. @property (nonatomic,assign) NSMutableData *receivedData; @end ViewController.m #import ViewController.h @interface ViewController () @end @implementation ViewController @synthesize receivedData; - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"didReceiveResponse"); [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"didReceiveData"); [receivedData appendData:data]; NSLog(@"%d",[receivedData length]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"connectionDidFinishLoading"); NSLog(@"%d",[receivedData length]); } - (IBAction)button_login:(id)sender { NSLog(@"Clicked on button_login"); NSString *loginScriptURL = [NSString stringWithFormat:@"http://www.website.com/app/scripts/login.php?"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginScriptURL]]; NSString *postString = [NSString stringWithFormat:@"&paramUsername=user&paramPassword=pass"]; NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody:postData]; // Create the actual connection using the request. NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; // Capture the response if (theConnection) { NSLog(@"theConnection is succesful"); } else { NSLog(@"theConnection failed"); } } @end

    Read the article

  • Getting Notifications in Background Mode iOS?

    - by Pau Senabre
    I'm trying to get Notifications in Background Mode by running a method every minute to see if there are new notifications. This works great in Active Mode, but I saw for background mode it is restricted to 7 keys. I enabled the Background Mode with the option Background Fetch, but seems like the method is being called but it's not complete. In AppDelegate I'm calling: - (void)applicationDidEnterBackground:(UIApplication *)application { //This has a Timer to execute every minute [self GetNotifications]; //This executes a NSMutableURLRequest *request //giving back the JSON data with the notifications } I would like to do something like Facebook does for Notifications. Any idea how to do this?

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >