Feature request > Network

Airprint support - Possible ?

<< < (4/4)

Neurox:
Hi Trucidare,
I've tested your code but I received this error "expected identifier or '(' before string constant" for Extern "C" declarations.
My XCode version is 3.2.5

trucidare:
you need to put the code in a .mm file because its objc++ sorry i forget this

Neurox:
Now compile, but nothing happens.
I added the NSLog into various points of code to see what happens :

--- Code: (glbasic) ---//
//  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];
}

--- End code ---

This is result from debugger console :

--- Code: (glbasic) ---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

--- End code ---

trucidare:
cant say - on simulator it works fine, i tested with a gif file. i think i enable airprint via hack and test on real device

Neurox:
I'm crazy out.
I've made test and test and test
but the app don't print to my HP printer and not appear the window of configuration airprint  :rant:

Navigation

[0] Message Index

[*] Previous page

Go to full version