Thursday, December 23, 2010

Image upload in iphone

Hi
Today I am sharing image browse and image upload tutorial with you..
Call following method for uploading photo you need to pass image data and file name of your image
Other thing you need small php code for uploading..

  







Please make sure your upload directory have read/write permission 
<?php
$uploaddir = 'photos/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;
         if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){
         echo "YES";
         }else{
         echo "NO";
         }
?>


- (NSString *)uploadImageFunction:(NSData *)imageData filename:(NSString *)filename{
   
    // Please Specify your php script Url here
     NSString *urlString = @"http://127.0.0.1/iphone/uploader.php";
   
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
     
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
   
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",filename]] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];
   
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    return (returnString);
}
you can download zip and php script from here.

Friday, December 17, 2010

Let get start work on blog agian.

Hi friends,

Lets start exploring cocoa. From a couple of months I was departed from my blog..
And the phenomenon of learning was stopped during that period. I have a few things to share
with you.

Wednesday, August 18, 2010

Installing an Application for Testing Over iPhone/iPod



The developer sends you an archive containing two files: the application and a provisioning profile.
You need to install both files into iTunes to be able run the application on your device.
After opening the archive:
  1. Drag the provisioning profile (the file with the .mobileprovision extension) to the iTunes Library group.
  2. Drag the application (the file with the .app extension) to the iTunes Library group.
    The application appears in the Applications list.
  3. Sync your device.
    If the version of iPhone OS on your device is earlier than the test application can run on, you need to update your device with the current release of iPhone OS.

Tuesday, July 27, 2010

UIView With Rounded corners

For Rounded Corners of UIView You Can use the following Code..
But you have to import first....
#import <QuartzCore/QuartzCore.h>

aView.layer.cornerRadius=8.0;
aView.layer.masksToBounds=YES;


cheers
Mandeep

Thursday, June 3, 2010

PDF Reader on iphone and ipad

hey
I found that beginner face problem in my previous post related to the pdf file reading on the iphone / ipad. so I upload a sample application and you can download from here.

PDFReader.zip

please ask feel freely any thing regarding iphone/ipad programming

Thursday, May 6, 2010

Colored UITabBar / Custom Color to UITabBar

hi friends
there is a simple way to set color of your UITabBar

CGRect frame = CGRectMake(0.0, 0, 320.0, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];

[v setBackgroundColor:[[UIColor alloc] initWithRed:1.0 green:1.0 blue:0.0 alpha:0.6]];

[tabBar insertSubview:v atIndex:0]; //tabBar is object of your UITabBar

Thursday, April 22, 2010

How to show PDF document/file on iphone / ipad.

Hi Guys.
Simple way to show pdf file on UIView. You just use the following class and alloc your UIView with PDFView class.
PDFView.h
#import
@interface PDFView : UIView {
CGPDFDocumentRef pdf1;
int pageNo;
}
-(void)drawInContext:(CGContextRef)context pno:(int)pageNo;
-(int)numberOfPages;
@end

PDFView.m

#import "PDFView.h"

@implementation PDFView

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("iphoneos.pdf"), NULL, NULL);
pdf1 = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CFRelease(pdfURL);
self.backgroundColor = [UIColor whiteColor];
self.opaque = YES;
}
return self;
}

- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()];
}
-(int)incrementPage :(int)no{
pageNo =no;
return pageNo;
}

- (void)dealloc {
[super dealloc];
}
-(void)drawInContext:(CGContextRef)context{
// before we start drawing.
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// Grab the first PDF page
CGPDFPageRef page = CGPDFDocumentGetPage(pdf1, pageNo);
// We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing
CGContextSaveGState(context);
// CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any
// base rotations necessary to display the PDF page correctly.
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true);
// And apply the transform.
CGContextConcatCTM(context, pdfTransform);
// Finally, we draw the page and restore the graphics state for further manipulations!
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
}
//Returns Number of Pages
-(int)numberOfPages{
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("iphoneos.pdf"), NULL, NULL);
pdf1 = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
int noOfPage =CGPDFDocumentGetNumberOfPages((CFURLRef)pdf1);
return noOfPage;
}
@end
And your Viewcontroller class, just implement the following code

UIView *myView=[[PDFView alloc]initWithFrame:rect];
int totalpage = [myView numberOfPages];
[myView drawRect:CGRectMake(0, 0, rect.size.width, rect.size.height)];
[self.view addSubView:myView];

Monday, April 5, 2010

Transparent Background on iPhone UIWebView

Simple solution to creating a UIWebView with a transparent background:

  • set your background color of the UIWebView to clear
  • set the css for the body to background-color: transparent
  • here's the bugger... set the opaque property of the UIWebView to NO
Code
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 310,450)]; self.bounds.size.height-60)];
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
[self.view addSubview:webView];
cheers

Japji Sahib on iphone

Past week, i upload new application on the app store. Japji Sahib reader.






http://itunes.apple.com/in/app/japji-sahib-punjabi/id364602780?mt=8

Monday, March 22, 2010

Last Week another release on itunes

Last friday, me and amit did release the you and me 'nought & cross' on the itunes stores.
As amit came in team, the speed of development should accelerate.

Wednesday, March 17, 2010

How to get Iphone device id for Provisioning.

First Way

1) Connect your iPhone/iPod Touch to your computer if it isn’t already connected
2) Launch iTunes
3) Click on the text “Serial Number:” in the “iPhone” section of the Summary tab.
4) The serial number will be replaced with the Identifier.
5) And U will get the 40 digit Identifier.

Second Way
1) Install the iPhone Configuration Utility if it is not already installed. [http://www.apple.com/support/iphone/enterprise/]
2) Connect your iPhone/iPod Touch to your computer if it isn’t already connected
3) Launch the iPhone Configuration Utility
4) If your iPhone/iPod Touch is not automatically selected – click on it’s entry at the bottom of the left-hand column
5) At the top of the screen, click on the “Export” button
6) In the save dialog box that opens, change the “Export type:” to “Device UDIDs”

Monday, March 8, 2010

Earn smile and kcard Magic with new looks is now available on App store

Hi guys
kCard magic is now released with new look. and After new look, in first day downloads is more than 250.

last week earn smile is also released on the app store.


downloads







Friday, February 19, 2010

kTrivia Geography and ithishome released.

hi Guys,
Past 2 weeks great for me. My developed two more applications release on the itune store.
Hope fully by end of this month, we will release two more games on itune store.
Thanks

kTrivia Georaphy


ithishome


Friday, February 12, 2010

Drawing circle on UIView :iphone

Drawing circle on UIView.

Circle.h

#import

@interface Circle : UIView {


}

@end

Circle.m

#import "Circle.h"

@implementation Circle

- (id)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

// Initialization code

}

return self;

}

- (void)drawRect:(CGRect)rect {

CGRect leftOval = {10, 160, 70, 70};

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.5);

CGContextAddEllipseInRect(context, leftOval);

CGContextFillPath(context);

}

- (void)dealloc {

[super dealloc];

}

@end

Tuesday, February 9, 2010

kcard Magic crosses over 1000 Downloads

hi guys
yesterday i got the news that kcard magic crosses over 1000 download in first week.
hoping that its user increase every second.
Mandeep

Friday, February 5, 2010

Apple Reject my application.

Yesterday I got review of my application kTrivia Geography from Apple. It cannot be launched on App Store because it violates section 3.3.6 of the iPhone Developer Program License Agreement:

Now I have made some changes in it. Hope fully this time apple will have no problem with my game.


Tuesday, February 2, 2010

How to determine Which model of iphone/ipod used

Include these classes

#include "sys/types.h"

#include "sys/sysctl.h"



Use this method for the Determine platform.

#pragma mark -

- (NSString *) platform

{

size_t size;

sysctlbyname("hw.machine", NULL, &size, NULL, 0);

char *machine = malloc(size);

sysctlbyname("hw.machine", machine, &size, NULL, 0);

/*

Possible values:

"iPhone1,1" = iPhone 1G

"iPhone1,2" = iPhone 3G

"iPhone2,1" = iPhone 3GS

"iPod1,1" = iPod touch 1G

"iPod2,1" = iPod touch 2G

*/

NSString *platform = [NSString stringWithCString:machine];

free(machine);

return platform;

}


Saturday, January 30, 2010

My iphone Game released on apple Store

My first keyss iphone game (kCard Magic) release on apple store.
http://itunes.apple.com/us/app/kcard-magic/id352730085?mt=8
And Second one in queue for approval.