Now compile, but nothing happens.
I added the NSLog into various points of code to see what happens :
//
// Airprint.mm
//
//
// Created by James on 21/07/11.
#import <UIKit/UIKit.h>
@interface AirPrintGLB : NSObject <UIPrintInteractionControllerDelegate>
@end
@implementation AirPrintGLB
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
NSLog(@"Init code");
}
return self;
}
-(int) GLBAirPrint:(const char *) imagePath
{
NSLog(@"Inside function");
NSString *path = [[NSString alloc ]initWithCString: imagePath];
NSData *myData = [NSData dataWithContentsOfFile: path];
NSLog(@"Img: %@ ",path);
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if (![UIPrintInteractionController isPrintingAvailable])
{
NSLog(@"Sorry printing not supported!");
return -1;
}
if(pic && [UIPrintInteractionController canPrintData: myData] ) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Error accoured!");
} else {
NSLog(@"Tadaaaa");
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
} else {
NSLog(@"Error with myData");
return 0;
}
NSLog(@"Out from function");
return 1;
}
@end
extern "C" int GLBAirPrint(const char* file);
extern "C" int GLBAirPrint(const char* file) {
AirPrintGLB *printInfo = [[AirPrintGLB alloc]init];
return [printInfo GLBAirPrint:file];
}
This is result from debugger console :
set cdir to: /var/mobile/Applications/3849DEC0-1EFA-4732-9BFE-710E0786C2B2/AirTest.app
exepath=curdir= /var/mobile/Applications/3849DEC0-1EFA-4732-9BFE-710E0786C2B2/AirTest.app
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
Init Finalized
set cdir to: Media
2011-08-02 08:41:58.479 AirTest[773:6503] Init code
2011-08-02 08:41:58.483 AirTest[773:6503] Inside function
2011-08-02 08:41:58.490 AirTest[773:6503] Img: /var/mobile/Applications/3849DEC0-1EFA-4732-9BFE-710E0786C2B2/Documents/pollo.png
[Switching to thread 13315]
2011-08-02 08:41:58.653 AirTest[773:6503] Out from function