Thursday, 12 September 2013

Problems in uploading binary again - Security.h issues

It makes confusion when this error appears after once you've already submitted the same binary/app before.

To resolve it, just set the iOS distribution provisions once again in Project and Target Build settings.

Saturday, 31 August 2013

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

If the exception appears like this :


Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

then you would have given wrong path to your file in the code. Either for an example an audio file or image or else given wrong file format extension.

So, have a look whether you've given the correct path in your project directory and the problem will be solved :)

Wednesday, 28 August 2013

UINavigation in iPhone Example Code

If you've created custom button and on touch event navigation is not done then you should put this code in your app delegate file.

AppDelegate.m 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[CoRoViewController alloc] initWithNibName:@"CoRoViewController" bundle:nil];
    } else {
        self.viewController = [[CoRoViewController alloc] initWithNibName:@"CoRoViewController" bundle:nil];
    }
    
UINavigationController *contrl = [[UINavigationControlleralloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = contrl;
    [self.window makeKeyAndVisible];
    return YES;


}

Tuesday, 27 August 2013

framework not found in iPhone

Due to miscellaneous reasons those frameworks which were appearing in your library, now when you open up your project it doesn't show you and instead appears in red letters framework name.

First check your XCode app framework directory : would be in such path

Applications/Xcode2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks

if you can't see it there then open up your system library : would be in such path

System/Library/Frameworks

if you find your framework required there then just copy it and paste it to the above framework directory and issue will be resolved.

Thursday, 8 August 2013

Screen orientation not working iOS 7

Your screen will not get landscape even if you turn the phone. This is just because in iOS 7 beta, you would have turned on portrait orientation lock. 

The fifth option in the image. So tap and turn it off and you will be able to use apps like google and others in landscape view.






Monday, 5 August 2013

how to declare an object in Objective C language ?

There are two ways :

Myclass *obj1 ;  // strong type 

id obj1; // weak type - more flexible in use

Objective-C supports both strong and weak typing for variables containing objects. Strongly typed variables include the class name in the variable type declaration. Weakly typed variables use the type id for the object instead. Weakly typed variables are used frequently for things such as collection classes, where the exact type of the objects in a collection may be unknown. If you are used to using strongly typed languages, you might think that the use of weakly typed variables would cause problems, but they actually provide tremendous flexibility and allow for much greater dynamism in Objective-C programs.


what are ivars in programming ?

"ivars" are nothing but just those instance variables declared in the class.

e.g. in Objective C code

@interface Myclass : BaseClass
{
         int count;
         float get;          // instance variables / ivars / data members

}

Difference between #import and #include in Objective C code ? iPhone/ XCode programming

#import and #include are like same. They perform the similar thing but the only difference is that #import makes sure that the same header file hasn't included again.

It is preferred to write #import over #include in your code. 

- Reference Learning from iOS Developer Library

Saturday, 27 July 2013

"Software on this iphone/ipod touch has expired" - iOS 7 Error - Not working - Developer

*This will appear when you're using the older beta and haven't upgraded and also when you haven't register your device on your apple developer account. Your device will act crazily.

*So, to resolve this first register device on your developer account. Then start your device and will ask you to confirm your device and will ask you to login from your Apple ID. So once you do it, it's ready again.

Apple's official steps to perform/install is as under :

 iOS beta Software Installation Guide

Overview

Pre-release versions of iOS software are available to develop apps that take advantage 
of the latest features of iOS and to test existing apps for compatibility. Pre-release 
software is intended only for installation on development devices registered with Apple's 
iOS Developer Program. Be sure to back up your devices prior to installing iOS beta 
software. 
Attempting to install this version of iOS in an unauthorized manner could put your 
device in an unusable state, which could necessitate an out of warranty repair.
Devices updated to iOS beta may not be restored to earlier versions of iOS. Registered 
development devices will be able to upgrade to future beta releases and the final iOS 
software.

System Requirements

iOS 7 beta supports iPhone 4, iPhone 4S, iPhone 5, iPod touch (5th gen), iPad 2, 
iPad with Retina display, and iPad mini. iOS 7 beta software should be installed using 
the latest released version of iTunes (http://www.apple.com/itunes).
Registering your Device
Before installing iOS beta software your device needs to be registered in the 
Certificates, Identifiers & Profiles area of Member Center. 

To register your device:
1. Locate the Unique Device Identifier (UDID) for your device using iTunes or Xcode

Using iTunes

a. Connect your device to your Mac and launch iTunes 
b. In iTunes, select your device in the source list on the left 
c. On the Summary tab, click on the Serial Number label to reveal the Identifier 
field and the 40 character UDID string
d. Control-Click on the Identifier (UDID) label and then choose Copy Identifier 
 (UDID)


Using Xcode

a. Connect your device to your Mac and launch Xcode 
b. Open the Organizer from the Window menu and select your device
c. Highlight the 40 character UDID string in the Identifier field 
and copy it

2. Login to the Certificates, Identifiers & Profiles area of Member Center and click the 
‘Devices’ link under iOS Apps
3. Click the ‘+’ symbol to begin the registration process
4. Give your device a name and paste the UDID obtained from iTunes/Xcode
5. Click continue and confirm your entry to complete the registration process

Installing iOS beta Software on your Device

1. Download the iOS beta software restore image for your device from the iOS Dev 
Center
2. Launch iTunes on your Mac
3. Hold the Option key and click the Restore iPhone/iPad/iPod button
4.Select the iOS beta software restore image from step 1 and click Open to begin 
installation
5.After installing the beta, your device will reboot and will require a network connection 
to complete activation
Reporting Feedback
To report any bugs, use the Apple Bug Reporter on the Apple Developer website 
(https://developer.apple.com/bug-reporting/). Additionally, you may find information in 
the iOS 7 beta area of the Apple Developer Forums (http://devforums.apple.com/
community/ios/).

- This contents are taken from apple's website for helping developers and readers of this blog.



Tuesday, 23 July 2013

How to play sounds in iOS - Xcode ?

There are basically two methods to play sounds, accomplished using two different frameworks :

1. AuidoToolbox framework
2. AVFoundation framework

The difference between AudioToolbox and AVFoundation framework is that AudioToolbox is used for short lengthen sounds whereas the AVFoundation is used for longer sounds.

In AVFoundation, when one sound is being played and the next is turned on then the previous one would be stopped.

Examples for both these will be published in upcoming posts :)

Thursday, 4 July 2013

Problems in Xcode 4.6 - Security/Security.h file not found - Lexical Error - UIKit framework

After working hard to resolve this error appearing while creating a build for the project, I resolved it. This is because of the problems with the Xcode version 4.6

Update your xcode to latest version 4.6.3 and this issue will be easily resolved and there won't be any of such errors :)

Saturday, 29 June 2013

How to use Swipe Gesture Recognizer iPhone ?

ViewController.h

@interface CoRoViewController : UIViewController<UIGestureRecognizerDelegate>

{
    UISwipeGestureRecognizer *gesture;


}

ViewController.m

-(void)viewDidLoad
{

 /* SWIPE GESTURE CODE */
    
    gesture = [[UISwipeGestureRecognizer alloc]init];
    [gesture setDirection:UISwipeGestureRecognizerDirectionLeft]; // you can use right or left ;)
    [gesture addTarget:self action:@selector(methodcalled)];
    
    gesture.delegate  = self;
    [self.view addGestureRecognizer:gesture];
}

-(void)methodcalled
{
      // Code you want to perform
}

Have fun :)

How to hide Navigation Bar ?

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

How to show Hidden Files on Mac ?

Open Terminal and write command :

defaults write com.apple.Finder AppleShowAllFiles TRUE
killall Finder

To hide the files once again :

defaults write com.apple.Finder AppleShowAllFiles FALSE
killall Finder

Tuesday, 23 April 2013

iCloud Backup alert problem in iOS device - resolution !

If you're seeing this alert message in your device, which is not going away and sticking on screen then here's the solution.

It won't work even if you will try to turn off the device. So, all you need to do is,

* Hold on the home screen button with "turn off" switch for around 10 seconds till Apple logo appears and then it will work okay ! (what we do to take a screenshot for ten seconds)

* Note : Don't worry, this reset won't erase any of your data.

Monday, 22 April 2013

How to set default text or hint in UITextField ?

In textfields, sometimes we need to show some default message which is a hint which disappears when gets focused or is in editing mode. So, for this do you the placeholder property of textfield.







For this just write the text you want to show in the field placeholder in property window.



Password and Confirm Password in UITextField Xcode

You can write the code below on your button touch event of either sign up or login. This will check whether the strings/passwords written in both UITextFields are same or not and will prompt an alert message :

iif ([self.pwd.text isEqualToString:self.confirmpwd.text])
    {
        UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Message" message:@"successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
        
        [alert show];
    }
    
    else
    {
        UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Message" message:@"Password mismatch" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        
        [alert show];
        
    }

Password validation in UITextField

Code for password validation is as below, written in textFieldDidEndEditing method of UITextField delegate :

*viewcontroller.h
Example :

@interface SignUpViewController : UIViewController<UITextFieldDelegate>
@property (nonatomic,retain)IBOutlet UITextField *pwd;

*viewcontroller.m

@synthesize pwd;

- (void)textFieldDidEndEditing:(UITextField *)textField
{


   if (textField == pwd)
    {
        int numberofCharacters = 0;
        BOOL lowerCaseLetter,upperCaseLetter= 0;
        if([pwd.text length] >= 10)
        {
            for (int i = 0; i < [pwd.text length]; i++)
            {
                unichar c = [pwd.text characterAtIndex:i];
                if(!lowerCaseLetter)
                {
                    lowerCaseLetter = [[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:c];
                }
                if(!upperCaseLetter)
                {
                    upperCaseLetter = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:c];
                }
                /*if(!digit)
                {
                    digit = [[NSCharacterSet decimalDigitCharacterSet] characterIsMember:c];
                }
                if(!specialCharacter)
                {
                    specialCharacter = [[NSCharacterSet symbolCharacterSet] characterIsMember:c];
                }*/
            }
            
            if(lowerCaseLetter && upperCaseLetter)
            {
                //do what u want
            }
            else
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                message:@"Please Ensure that you have at least one lower case letter, one upper case letter, one digit and one special character"
                                                               delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
            
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:@"Please Enter at least 10 password"
                                                           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

    }
}

Email validation in UITextField

Create a function for validating email like the code below :


- (BOOL)validateEmail:(NSString *)emailStr 
{

  NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
   NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:emailStr];

}

UITextField delegate has a method textFieldDidEndEditing, write the code below to display an alert message when email is not valid :

if (textField == email)
    {
        
if(![self validateEmail:[email text]])
        {
            // user entered invalid email address
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Enter a valid email address." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert show];
           
            //email.text=@"";
        }
    }

How to use UINavigationViewController in Xcode ?

Hello World, 

I thought that navigation is one of the useful thing we do, so thought for a little help making a tutorial. So, here's how we do it :

If you are using storyboard then there's no need of this but if you are going through xib then learn using this method.

So, first of all do include the below code in your appdelegate.m file otherwise your navigation would never work :




Now, on a button touch event, we perform the navigation to the another screen. So, I've created an object of secondview here.

Watch the video to understand it well :)

Sunday, 14 April 2013

How to get longitude and latitude for an iPhone App code ?

It's really easy doing this using CoreLocation.framework. Fast learning tutorial is as below :


Open your AppDelegate.m, and import the "CoreLocationViewController.h".
// Add this line on top of your AppDelegate.m

#import "CoreLocationViewController.h"
Change the application:didFinishLaunchingWithOptions: method in your 'AppDelegate.m' with the code below. First of all create a 'CoreLocationViewController'. Then create a UINavigationController with the 'CoreLocationViewController' as the RootViewController.
Now we need to add the UINavigationController as a subview of the UIWindow.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
 
    CoreLocationViewController *myCoreLocationViewController = [[CoreLocationViewController alloc] 
                                                      initWithNibName:@"CoreLocationViewController" 
                                                      bundle:[NSBundle mainBundle]];
 
    UINavigationController *nav = [[UINavigationController alloc] 
                                   initWithRootViewController:myCoreLocationViewController];
 
    [[self window] addSubview:[nav view]];
 
    [self.window makeKeyAndVisible];
    return YES;
}

Open your 'CoreLocationViewController.xib' and add two objects of type UILabel. Switch to the 'Assistant Editor'. Select the UIView and insert outlets for the two newly added objects. Give the labels the following names. One label 'locationLabelOne' and the other lable 'locationLabelTwo'. You could create outlets by 'ctrl-clicking' a object and drag it to the left side of the 'Assistant Editor'. This two labels are later used to fill with the longitude and latitude of your CoreLocation service.
Now it's time to create your CoreLaction service. We need a CLLocationManager to get the current locationof the users device.
Open your 'CoreLocationViewController.h' and fill it as the code below. First import the CoreLocation service, after that make a CLLocationManager object.

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
 
@interface CoreLocationViewController : UIViewController <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}
@property (retain, nonatomic) CLLocationManager *locationManager;
@property (retain, nonatomic) IBOutlet UILabel *locationLabelOne;
@property (retain, nonatomic) IBOutlet UILabel *locationLabelTwo;
 
@end

After that it's time to use the CoreLocation service in your 'CoreLocationViewController.m'. Open your file and change or add the methods below. First of all synthesize your before created CoreLocation service.
#import "CoreLocationViewController.h"
 
@implementation CoreLocationViewController
@synthesize locationManager; 
@synthesize locationLabelOne;
@synthesize locationLabelTwo;
 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
The second change is in the viewDidLoad: method. Initialize your CoreLocation service by changingthat method with the code below. 
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
 
    [self setLocationManager:[[CLLocationManager alloc] init]];
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    [locationManager startUpdatingLocation];
}

Now it's time to add the new locationManager:didUpdateToLocation:fromLocation: methodFill the method with the code below. This method is called by the CoreLocation service when the device is going from point a to point b. In this method you've the longitude and latitude, and you could do something with that.
In this situation we're adding the current location to the two above added UILabels. You could read the longitudeand latitude from your screen.

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
 
 
    [locationLabelOne setText:[NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]];
 
    [locationLabelTwo setText:[NSString stringWithFormat:@"%f", newLocation.coordinate.longitude]];
}

Finished! Now you're ready to run your project and use the CoreLocation service to get the longitude andlatitude of the users device.

A reference link and code is on this site : 

Find a detailed tutorial and code on this link !

Saturday, 13 April 2013

Why to use clean in XCode ?

Well, many a times, we see errors which are irrelevant and we think this doesn't make sense. When we code and error appears, we directly resolve some of the lines above and when we see below there are some errors still there.

These are actually resolved already but keep on appearing. So, if you will keep on seeing and thinking that these are the errors and you will try to resolve them, you will be in a mess.

So, rather keep using "clean" frequently as it will clean unnecessary error messages those are already resolved.

Cannot use super because it is a root class error in Xcode project !



Getting an error "cannot use super because it is a root class" and wasn't able to find the proper solution. After a while found that have misplaced the name so "self" calling was not working.

This error may appear either you haven't written @interface "" @end or misplaced the name of it or written a different name after "@implementation"

e.g. in above image, as I was working on CoRoViewThree_iPad, when I replaced "Four" with "Three" and similarly Three instead of Two in @implementation, the error resolved.


Such kind of error mostly occurs when we copy the codes of different view controllers and forget to change the names.




How to make an invisible button in iOS App xib ? Hidden Vs. Custom type

I was developing an app where I needed to replace the existing buttons with the invisible ones, means in the background I've set my useful image that replaces buttons.

There were some sound play events on button touch up inside. I firstly, tried making the buttons hidden by ticking one of the properties of making a button hidden. 


The problem I faced was that on running the app the sounds were not being played. Tried a little to resolve it and the solution was :

* To select the button type to custom, that makes the button disappear and works like hidden. So now, sounds got played and it worked !


And in order to show the button getting pressed, tick the option of "shows touch on highlight"

Sunday, 31 March 2013

iOS 6 views/layout backward compatibility resolution

How to solve the problem of layout of views when creating app supported for iOS 6.1 and the previous version of it ?

I updated my xcode to version 4.6 ! The first problem I faced was the layout issue with the screens. As I wanted to develop app that supports not only iOS 6.1 but also with the backward compatibility with the previous versions.

After I designed the screen, I ran it on 6.1 simulator, it worked well. Then I chose the hardware iPhone ratina 3.5 and it got weird. Images got misplaced and didn't work well.

I tried to have a look on many forums but couldn't find the easy resolution, so I spent some time and was changing properties and was testing. 

The solution is :

  • Go to the size inspector
  • See the left box ?
  • Set Origin to the centre 
  • Don't use auto layout, it is for vertical and horizontal view settings / Make it unchecked   
  • If it's just strict portrait then go this way.
If you have more queries, you can write me here or contact me on facebook.com/harshsthaker