Feature request > Network
Airprint support - Possible ?
Neurox:
I put in all the points the NSLog(), I discovered that the print is sent to the printer without problems (even if it doesn't print anything) and exit the function but it seems that GLBasic isn't able to control of the screen.
Moebius:
I deleted anything pertaining to 'self' in the class, including the delegate, and if I understand correctly the action should never be recognised as 'complete'. The code is screwed up - find a better example on the internet.
trucidare:
the print controller is a shared thing and could be used outside from classes. but apple uses delegates in all shared things so i need the full code to make it workable
Moebius:
Apple page: http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Printing/Printing.html
print image code taken from: http://www.iphonedevsdk.com/forum/iphone-sdk-development/67176-airprint-tutorial-simple-print-file-30-lines-code.html
Good Luck! (I don't even understand delegates :giveup:)
trucidare:
very untested and not checked for syntax - please try someone - put them into .mm file
--- Code: (glbasic) ---//
// AirPrintGLB.mm
// AirPrintGLB
//
// Created by Hiro Kanakawa on 01.08.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AirPrintGLB : NSObject <UIPrintInteractionControllerDelegate>
@end
@implementation AirPrintGLB
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
-(int) GLBAirPrint:(const char *) imagePath
{
NSString *path = [[NSString alloc ]initWithCString: imagePath];
NSData *myData = [NSData dataWithContentsOfFile: 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 {
return 0;
}
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 ---
Tested in simulator:
--- Code: (glbasic) ---[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Accepted "test.gif" for printing (job #143896126, application/pdf, 1 pages){
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-state-changed - Job pending.{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Printing "test.gif" (job #143896126){
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Viewing "/var/folders/pg/t13mbqm1063d_8wggb6xjpch0000gq/T/PrinterSimulator.RSqXpC/143896126.pdf".{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] "POST /printers/save HTTP/1.1" 200 4093918 - successful-ok{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-state-changed - Job printing.{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Connecting to printer.{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] "POST /printers/save HTTP/1.1" 200 382 Get-Job-Attributes successful-ok{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Undefined error: 0{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-completed - Job completed.{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Accepted connection from 192.168.125.1:49418 (IPv4){
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] "POST /printers/save HTTP/1.1" 200 295 Get-Printer-Attributes successful-ok{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Closing connection from 192.168.125.1:49418 (IPv4){
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] "POST /printers/save HTTP/1.1" 200 382 Get-Job-Attributes successful-ok{
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Closing connection from 192.168.125.1:49416 (IPv4){
NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version