Thursday, October 20, 2011

Swipe to delete from UITable view

In order to achieve swipe to delete option use following code snippet:

#pragma for deleting element from tableview

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
   
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if(editingStyle == UITableViewCellEditingStyleDelete) {
        [Array2 removeObjectAtIndex:indexPath.row];
        [Array1 removeObjectAtIndex:indexPath.row];
        [TableName_obj reloadData];
    }
}


Saturday, June 11, 2011

Generate MD5 Hash of a string in iphone sdk

This function will help you generate MD5 hash of a given string.

Include following class your project :

md5.h

+ (NSString *)getMD5FromString:(NSString *)source;

md5.m

+ (NSString *)getMD5FromString:(NSString *)source{
  const char *src = 1;
  unsigned char result[CC_MD5_DIGEST_LENGTH];
  CC_MD5(src, strlen(src), result);
    NSString *ret = [[[NSString alloc] initWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ] autorelease];
    return [ret lowercaseString];
}

Tuesday, May 31, 2011

Interview question part 3

  • Basic Questions:
  • identify basic OO concepts and the keywords Objective-C uses (interface, implementation, property, protocol, etc)
  • what is a designated initializer, what is the pattern for the initializers and why ( if (self = [super ...] ) )
  • basic memory management topics, like ownership retain/release/autorelease
    • what happens if you add your just created object to a mutable array, and you release your object
    • what happens if the array is released
    • what happens if you remove the object from the array, and you try to use it
  • trick: garbage collection on iPhone
  • autorelease pool usage
  • property declarations ( assign, nonatomic, readonly, retain, copy )
    • trick: ask about the nonexistent atomic keyword, what does atomic mean
    • ask on how to correctly implement a retaining setter property
    • ask about the circular reference problem and delegates being usually saved with assign rather then retain
  • what is the difference between the dot notation and using the square brackets
    • what happens when we invoke a method on a nil pointer
    • difference between nil and Nil
  • what is KVO and related theory + methods to use when observing
    • does KVO work with ivars too?
  • protocols – maybe: main difference between c#/java interface and protocols
    • what to do in a situation when a class doesn’t implement a method from a protocol
  • what about multiple class inheritance
  • what is fast enumeration
  • class methods vs instance methods
    • visibility of methods
  • what is an actual class in Objective-c (struct)
    • ask about the isa member
    • ask about isKindOfClass isMemberOfClass
  • root classes: NSObject, NSProxy
    • how does proxy-ing work
    • how to fake multiple class inheritance
  • id type
    • what happens during compilation if we invoke a method on an variable with the type id
    • what happens runtime if the method exists
    • what happens if the methods doesn’t exist
    • pro and cons of using the type id
    • what happens here(compile + runtime): NSString *s = [NSNumber numberWithInt:3]; int i = [s intValue];
  • what are class categories and the () category
  • what is an informal protocol
  • what is a delegate, how to create one, and use one
  • what is a selector, how to do a perform selector
    • how to delay executing a selector
    • what to do when the selector has more paramters (NSInvocation>
    • how to start a selector on a background thread
  • how to start a thread
    • what is the first thing to do on a thread (autorelease pool)
    • what is a runloop, and one very common place where it is used (timers, nsurlconnection)
  • how to download something from the internet
    • what is the difference between a synchronous and an asynchronous request
    • small task: explain how to download an image from the internet, and show this in an image view – all this after a button is tapped on the view
  • what are notifications, how to use them
  • what is a memory warning, how do we respond to it
—- A bit more advanced topics —-
  • when to use retainCount (never, and why)
  • why shouldn’t we invoke instance methods in an initializer and the dealloc
  • NSCoding, archiving
  • NSCopying, why can’t we simply use our own objects as key in a dictionary, what to do to solve the problem ( and the difference between a shallow and a deep copy)
—- UIKit related —-
  • what is a view, and a window
  • difference between a view’s bounds and frame
  • what is the resolution of the current available devices, difference between points and pixels (starting with iOS4)
  • what is the responder chain, becomeFirstResponder
  • what do IBOutlet and IBAction mean, what are they preprocessed to
  • how do tableviews function
  • what about multithreading and UIKit
  • what to do when the keyboard appears and hides some parts of the UI that are important
  • why should we release the outlets in viewDidUnload
  • what is awakeFromNib, what is the difference between a nib and a xib
—- CoreData —-
  • what is a context
  • what about multi threading and core data usage
  • what is an NSManagedObjectId – can we save it for later if the application was stopped
  • what types of stores does core data support
  • what is lazy loading, how does this relate to core data, situations when this can be handy
  • how to ready only a few attributes of an entity
  • what is an fetch result controller
  • how to synchronize contexts
  • how could one simulate an NSManagedObject (i’m thinking of the fact that all the properties are dynamic and not synthesized)
Source : here

Friday, May 20, 2011

Simple bluetooth chat application for iPhone

One of the features available in iPhone OS 4.0 is the GameKit framework. The GameKit framework contains APIs to allow communications over a Bluetooth network. Using these APIs, you can create peer-to-peer games and applications with ease. Unlike other mobile platforms, using Bluetooth as a communication channel in iPhone is way easier than expected.

By using this framework you can ON bluetooth of your iPhone manually, but still there is no chance to OFF the bluetooth manually.

I had attached sample code of this application..its very simple to understand.

Steps to test a code:



Once the application is deployed to the two devices, launch the application on both devices. On each device, tap the Connect button. The GKPeerPickerController will display the standard UI to discover other devices .

After a while, both application should be able to find each other. When you tap on the name of the found device, the application will attempt to connect to it.
When another device tries to connect to you, you will see the popup. Tap on Accept to connect and Decline to decline the connection.

If you are connected, you can now enter some text and start sending to the other device. Data received from another device will be shown in an alert view .


And finally here you will get SOURCE CODE for this tutorial..


Thursday, January 27, 2011

Generating the Apple Push Notification SSL certificate on Mac:

Generating the Apple Push Notification SSL certificate on Mac:


1. Log in to the iPhone Developer Connection Portal and click App IDs

2. Ensure you have created an App ID without a wildcard. Wildcard IDs cannot use the push notification service. For example, our iPhone application ID looks something like AB123346CD.com.product.yoursiphone

3. Click Configure next to your App ID and then click the button to generate a Push Notification certificate. A wizard will appear guiding you through the steps to generate a signing authority and then upload it to the portal, then download the newly generated certificate. This step is also covered in the Apple documentation.

4. Import your aps_developer_identity.cer into your Keychain by double clicking the .cer file.

5. Launch Keychain Assistant from your local Mac and from the login keychain, filter by the
Certificates category. You will see an expandable option called “Apple Development Push Services”

6. Expand this option then right click on “Apple Development Push Services” > Export “Apple Development Push Services ID123″. Save this as apns-dev-cert.p12 file somewhere you can access it.

7. Do the same again for the “Private Key” that was revealed when you expanded “Apple Development Push Services” ensuring you save it as apns-dev-key.p12 file.

8. These files now need to be converted to the PEM format by executing this command from the terminal: openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12

9. openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12

10. If you wish to remove the passphrase, either do not set one when exporting/converting or execute: openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

11. Finally, you need to combine the key and cert files into a apns-dev.pem file we will use when connecting to APNS: cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

Please check with ios5, as i am not that much updated with push notification implementation in ios5.

Wednesday, January 19, 2011

Augmented reality (AR)

Hi,
Guys this week i had started with one new concept of Augmented reality (AR).I search lot for this concept but nothing is there on internet and still i am working to prepare demo on this.

Following is something about this big concept:

Augmented reality (AR) is a term for a live direct or indirect view of a physical, real-world environment whose elements are augmented by computer-generated sensory input,such as sound or graphics. It is related to a more general concept called mediated reality, in which a view of reality is modified (possibly even diminished rather than augmented) by a computer. As a result, the technology functions by enhancing one’s current perception of reality. By contrast, virtual reality replaces the real-world with a simulated one.

http://www.youtube.com/watch?v=DpmAyen4sv0



Very soon i will be here with one fantastic demo code on this.