Skip to main content

Posts

Showing posts from February 9, 2012

iPhone - How to handle errors at runtime

When writing code, there are many situations that must be treated as runtime errors : an alloc/init returns nil, a resource is not found, a [someClass canDoThis] returns NO for an absolutely-needed feature where YES would be the natural answer, ... For all these situations, I have written an exitWithMessage routine (that displays an alert box), and each class has a kill method that frees allocated memory. So... When in an init method, you have these kind of exceptions, I supposed you could do : [self kill]; [OneClass exitWithFatalErrorMessage]; return nil; - (void) exitWithFatalErrorMessage:(NSString*)message { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTable(@"Error" @"ErrorMessages", @"") message:message delegate:self cancelButtonTitle:NSLocalizedStringFromTable(@"Understood", @"ErrorMessages", @"") otherButtonTitles: nil]; [alert show]; [alert release]; } - (void)alertV

Convert an iPhone phone number format for a "dial-able” string

I am building an iphone app that reads a phone number from the address book and dial it (with some other things of course...:)). When I load the phone numbers from the AB they are in this following format: "1 (111) 111-1111" which is not "dial-able" when using this: fullNumber = [NSString stringWithFormat:@"%@%@", @"tel:", phoneNum]; Why is that happening? What would be the best way to approach this? How could I convert the phone number into a string of digits (with no spaces or "-")? Thanks.

What control should i use when doing this in objectice C

following are my snapshot please look at it: http://bit.ly/y7U05k or below is the attached image in this snapshot i have to make the boot control like images when i click image#1 then image#1 show on the upper side UIImageView i also define on the image... image#1 .. image#1000 so please help me what control's should i use, i think i should use UIScrollView but i don't know what is the heigh and width i should take for that because UIScrollView has only game of height and width and also how to define click control on them. please help and i am very thankful if u give me the code but don't mind .. thanks I want some slider look like .. i slide the below images

Developing a new app; is maintaining iOS 4 compatibility still worth it? [closed]

I am currently in the starting phase of developing a new iOS app (for both iPhone and iPad) for a client. I'm really indecisive if I should still support iOS 4 or not. I tried to find some statistics about the adoption of iOS 5, one of the only fairly recent articles that I could find was this one. This article shows that 59,16% of all users of Bump for iPhone were using iOS 5 or later as of December 30th of last year. The (free) app will not be out for another 1.5 to 2 months, my personal guess is that the iOS 5 adoption percentage will be pretty large by then. I fully realize that there is no single answer to this question, but I would like to know what your experiences with backwards compatibility are and if you think it is worth the hassle. I would really like to use the new Storyboard functionality of Xcode and I would also really like to use ARC (although I understand that it is partially useable with iOS 4 too). The app will also use quite a bit of JSON and which is no

Recursively traverse object in Objective-C

I'm converting diverse JSON objects to structured objects and want to iterate over all the nodes to process each one hierarchically. JSON framework supports conversion to an NSDictionary, which I thought was unstructured. I want to recursively iterate through each item and pay respect to the structure. How would this be done with either a dictionary or generic NSOBject? Example: - (void) processParsedObject:(NSDictionary *)obj { if (atTheEndOfTheTail) { NSLog(@"Object description: %@\n\n", obj.description); } for (id object in obj) { [self processParsedObject:object]; } } Update: I asked the question more clearly here (with answer): Recursively traverse NSDictionary of unknown structure

get ascii code from string in xcode for iphone app

hey just a couple quick noob questions about writing my first ios app. Ive been searching through the questions here but they all seem to address questions more advanced than mine so im getting confused. (1) All I want to do is turn a string into an array of integers representing the ASCII code. In other words, I want to convert: "This is some string. It has spaces, punctuation, AND capitals." into an array with 62 integers. (2) How do I get back from the NSArray to a string? (3) Also, are these expensive operations in terms of memory or computation time? It seems like it might be if we have to create a new variable at every iteration or something. I know how to declare all the variables and im assuming I run a loop through the length of the string and at each iteration I somehow get the character and convert it into a number with some call to a built in command. Thanks for any help you can offer or links to posts that might help!

Cocos2D iPhone - running actions on multiple targets + callback

I have an array of objects (objArray) and an array of actions (actArray). Both arrays are in order, I mean, object at index 0 of objArray has to perform action 0 on actArray. To make the explanation clear, lets imagine both arrays have 3 objects, obj0, obj1 and obj2. obj0 has to perform action 0 on actArray obj1 has to perform action 1 on actArray obj2 has to perform action 2 on actArray these 3 operations (or n, in the case of the array) have to happen simultaneously. When all animations end, I need the method animationsFinished to be called. How do I do that? I am beginning in Cocos. I have googled around and have not found any practical example around. I have found CCSpan but I don't see how this can be used with multiple objects each one with its own action. thanks.

Testing various versions of iPhone Safari

I am developing a jquerymobile App, and things are looking good in IOS5 with the most up-to-date version of Safari, I really need to test some older versions of Safari and its Webkit to ensure things are looking good for most browser versions. I realise I can fire up an old version of xcode with SDK4 , and test IOS4, but what I really need to test is the various versions of Safari, does anyone know how to do this? I'm assuming it is possible to upgrade Safari without upgrading your IOS.

How to return from "partial curl” type segue

I am attempting to use a partial curl segue to reveal an options view underneath my main view. This is identical to touching the "page curl" button in the bottom right corner of the Maps app. I can successfully execute the segue to the option view, my problem is returning to the main view. I'm hoping to replicate the reverse animation effect of the Maps app as the edge curls back flat and the main view is shown. It doesn't seem logical to create another segue to return back to the main view (what I would do if I were not using the partial curl segue) because the return segue is associated with the original segue. Thanks in advance for any help!

Is there a RESTful YouTube API for iOS?

I'm trying to access YouTube from within an iOS app, but the iOS SDK is a bit outdated and the source is abysmal. I'm trying to access the playlist of a particular account and show it as part of an app. Is there any API or URL endpoint I can use? Do I need to use the SDK, or can I manually craft HTTP requests using Objective-C? (I'm thinking LRResty or something similar.) Edit: Do I need to have an API key to use the RESTful API? If so, how do I obtain one?

Developing and selling web apps listed on apple web apps and equivalents such as android, windows etc [closed]

Do i need to pay a developer's fee of 99$ per annum if i want to list my web app on the apple web app store, or any other place for that matter (android etc.)? Can i ask user to come and pay for new features on my site through this web app? will I be breaching some archaic policy by doing that? This web app is complete on its own but user might want to have extra features which come at a price of course! Which merchant is the best for my basic needs. paypal comes to mind but is it my only option? this is my hobby. I have a separate day time job which does not involve software development. what do i need to do as far as paying taxes (if any) is concerned. am i liable to pay taxes? I do not want to create my own company etc. just because im developing this web app. By the way, if you intend to reply on tax-related questions, please understand I reside in England.

iPhone - How to test allocated objects returned by each memory call?

When writing an app, you always have to write alloc/inits, get autoreleased datas returned by the framework classes, ... This may be 70% of the code, almost each single line of what you write... So... How do those returned object must be tested, to know if each of these calls have returned a correct object ? Testing the returned value each time, for each call, and treating the exception if you get nil where you expected an allocated object ? Letting the app crash ? How this must be done ?

Custom UISegmentedControl like the Scope control in UISearchBar

I like to create a UISegmentedControl that looks like the scope button in UISearchBar. Do you know how to do it? Update: So I want to create a UISegmentedControl like this (please notice the appearance), this is not related with UISearchBar, I just want to make it LOOKS LIKE the scope buttons in UISearchBar.

create an Object and NIL value

I am used to have this in my code myClass.h @property ( strong, nonatomic ) ClassA *varA myClass.m varA = [[ClassA alloc] init]; if ( varA isEqual:nil ) NSLog@"var A is nil"); else NSLog@"var A is not nil"); this is a result from console var A is not nil I thought var A should be nil then. So my question is what does blue line do and why var A is not nil after all

Cocos2D iPhone - will this save memory?

When you create a sprite on cocos using a texture you allocate memory. Something like: CCTexture2D *textureProxy = [[CCTexture2D alloc] initWithImage:image]; CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; My question is: suppose I want several sprites using the same texture and I do CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy2 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy3 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy4 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy5 = [CCSprite spriteWithTexture:textureProxy]; Will I use 5 times more memory? (or in other words, will the texture be duplicated to each proxy or is the sprite just a "empty box" that references the original texture? If the later is the answer, then the memory usage for similar sprites are not that huge, right? thanks.

Iphone Push Notification Wrong Device Token

Finally,I found out the sandbox tokens,which were mixed with the production tokens,and I update the code,receive the error response from apple,when post a sandbox token to apple,the next tokens all failed....While the push msg was "$payload['aps'] = array('content-available' => 1); ",apple will push the msg ,but the device will not show this msg,when I find the wrong one,I delete it,and retest. There is an amusing problem of apple push notification service: when I generate a post notification for my device and send to apple's server,for a while,my device will receive the notification. But if I first post a notification by a wrong devicetoken,then post a right notification to my device,my device will be responseless,just like the push notification was eaten by apple? What wrong with this? I use php code for push service,here is the most important part: $payload['aps'] = array('content-available' => 1); while ($line = mysql_fetc

Create a persistent store for Core Data

I did the tutorial on apples site, the Core Data tutorial for iOS and i did this tutorial about 3 times to see if i was mistaken, But when i finish the tutorial, it says that the app should work and be able to add Events to the table view, but when i press the + button, the app crashes and the console says: Cannot do save operation. There is no persistent store How could i fix this? I checked my code and i have everything!! Thanks in advance!

""CCLayer" may not respond to … ”

Playing with cocos2d and this seems to come up in some instances of message passing. I have to admit, I'm not well versed in Objective-C yet as I'm reading through the book as I write some code. For people familiar with cocos2d, you have a CCLayer class. In my case, I have a GameLayer which has some children layers, like so: @interface GameLayer : CCLayer { CCSprite *_background; CCPanZoomController *_controller; CCLayer *_truckLayer; } I then have a special initWithLayers method to add my child layers within this layer: -(id)initWithLayers:(TruckLayer *)truck { if( (self=[super init])) { self.truckLayer = truck; ..... } Now if I ever send a message to self.truckLayer I get the following warning in Xcode: 'CCLayer' may not respond to 'getNextAvailableSpot' An example might be doing something like so: CGPoint nextSpot = [self.truckLayer getNextAvailbleSpot]; All this code compiles and runs successfully, so I'm curious as to w

how to add some space in uiwebview [closed]

Now I have an uiwebview ,but I need some space right and left of the text.and I just write code programmatically,don't use IB. m_webView = [[UIWebView alloc] initWithFrame:CGRectMake(11, 95, 298, 350)]; NSString * path = [[NSBundle mainBundle] bundlePath]; NSURL * baseURL = [NSURL fileURLWithPath:path]; NSString * htmlString = [NSString stringWithFormat:defString, NSLocalizedString(@"kTerms_and_Legal_content_text", nil)]; [m_webView loadHTMLString:htmlString baseURL:baseURL];

unarchiveObjectWithFile returns NSArray

I am working on NSKeyArchive and running into the problem... What I am having so far is 1.-(BOOL)archiveItem 2.{ 3. NSString *path = [self findPath]; 4. if ([NSKeyedArchiver archiveRootObject:items toFile:wishListPath]) 5. { 6. return YES; 7. }else{ 8. return NO; 9. } 10.} 11.-(BOOL)unarchiveItem 12.{ 13. NSString *path = [self findPath]; 14. self.items = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 15. NSLog(@"Class of items is %@",[self.items class]); 16. if (self.items == nil) 17. return NO; 18. else 19. return YES; 20.} In my header file, items is declared like @property (nonatomic, copy) NSMutableArray *items; However, line 15 shows that type of items is NSArray ( not NSMutablArray) Does anyone have an idea about this one,please help. All comments are welcomed. Thanks

UIKeyboardTypeNumberPad type letters?

I really want to make a keyboard that is the UIKeyboardTypeNumberPad but instead of it showing a 4 in a textfield when pressing the 4 button, i want it to highlight the G for about 5 seconds and while its highlighted, if i press again it goes to h then to i, and for all letters, so 2 would start A then b then c if clicked multiple times? i found out on IOS they have a built in one that does this, but its not exactly the UIKeyboardTypeNumberPad and its for japanese, it will show, and type in US but still some japanese around and is hard to use because its not a true full UIKeyboardTypeNumberPad. like 0 is space or go to next letter, not on the japanese one though. so how could i code this for my application?

Do apple native media player play Play-ready media files

I have been researching on whether we can create an app which will play Play-ready protected DRM video files in apple's native media player. But what I could collect is that apple will not allow DRM protected video files to be streamed or played through media player. However if this the case, how there exists solution like "Authentec downloadable agent" which can decrypt the files and play them from within the app? Also as per my R&D, the device should support play-ready file format. Hence now OEM's are launching phones like HTC, nokia with play-ready support. But how will we provide support on apple devices? Please, any inputs or thoughts on this will surely be helpful.

File Transfer Bluetooth GameKit [closed]

I want to transfer the file from one iphone/ipad to another via bluetooth.i have googled and found the gamekit which ca do the perr to peer network.i have integrated successfully.But when i run it only searches for iphone/ipad but unable to find any device.it search for unlimited time, Then i have checked manualy but unsuccesful. Specs :ipad :4.3.5 (8L1) and ipad: 4.3.3 (8j2) and third one is Iphone 4S Is it not possible to transfer ia bluetooth? What are the prerequisits for it if any? Regards, Aamir

post and delete method for ios devices

Adding a playlist to youtube account POST /feeds/api/playlists/PLAYLIST_ID HTTP/1.1 Host: gdata.youtube.com Content-Type: application/atom+xml Content-Length: CONTENT_LENGTH Authorization: AuthSub token="AUTHORIZATION_TOKEN" GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY <?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <id>VIDEO_ID</id> <yt:position>1</yt:position> </entry> delete playlist of youtube account DELETE /feeds/api/users/USERNAME/playlists/PLAYLIST_ID HTTP/1.1 Host: gdata.youtube.com Content-Type: application/atom+xml Authorization: AuthSub token="AUTHORIZATION_TOKEN" GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY HOW DO I SEND THIS BOTH METHOD TO YOUTUBE SERVER IN IOS AND GET RESULT. ihave all require data (e.g. token and allthat) but idont know how to send this post and delete method

How to pass the Value from UITextField from one VC to a string in another VC?

I have googled for this and even tried searching in many forums, also tried Singleton,etc but each time my 2nd VC'c string is returning a NULL value. RETRIVALTVC is my VC in which i'm expecting for the Value and IRTViewController is my VC having the TextField. I have imported all the header files. This is my RetrivalTVC RetrivalTVC.h #import<UIKit> NSString *string; @property (nonatomic, copy) NSString *string; In RetrivalTVC.m when i tried to read the value of string its returning NULL - (void)viewDidLoad{ [self list]; } - (NSMutableArray *)list{ NSLog(@"Value of string: %@",string); } This is my IRTViewController IRTViewConroller.h @property (weak, nonatomic) IBOutlet UITextField *searchTrain; -(IBAction)search:(id)sender //Action when Button is Pressed IRTViewController.m -(IBAciton)search:(id)sender{ RetrivalTVC *retriv = [[RetrivalTVC alloc]init]; retriv.string = searchTrain.text; //Here when i used NSLog its returning the value Plea