Hello, I’m having trouble getting this view to display. I believe I have configured it correctly, and tested in a fresh iOS Objective-C app with something very similar.
The PrintManager is created as a global JS module.
using Uno;
using Uno.UX;
using Uno.Collections;
using Fuse;
using Fuse.Reactive;
using Fuse.Scripting;
using Fuse.Controls;
using Uno.Compiler.ExportTargetInterop;
[UXGlobalModule]
public class PrintManager : NativeModule
{
static readonly PrintManager _instance;
public PrintManager () {
if(_instance != null) return;
Uno.UX.Resource.SetGlobalKey(_instance = this, "PrintManager");
AddMember(new NativeFunction("print", (NativeCallback)Print));
}
object Print(Context c, object[] args) {
Fuse.Scripting.Array pages = args[0] as Fuse.Scripting.Array;
for(int i = 0; i < pages.Length; ++i) {
debug_log "Page " + i.ToString() + ": " + (pages[i] as string);
}
string jobName = "Print";
if(args.Length > 1) {
jobName = args[1] as string;
}
string[] pagesImpl = new string[pages.Length];
for (var i = 0; i < pages.Length; i++) {
pagesImpl[i] = pages[i] as string;
}
PrintImpl(pagesImpl, jobName);
return null;
}
extern(!iOS) public void PrintImpl(string[] files, string jobName)
{
debug_log "Printing not supported yet.";
}
[Foreign(Language.ObjC)]
extern(iOS) public void PrintImpl(string[] files, string jobName)
@{
if([UIPrintInteractionController isPrintingAvailable]){
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
UIPrintInfo*printInfo = [UIPrintInfo printInfo];
[printInfo setOutputType:UIPrintInfoOutputGeneral];
[printInfo setJobName:jobName];
[printInfo setOrientation:UIPrintInfoOrientationPortrait];
[printController setPrintInfo:printInfo];
[printController setShowsNumberOfCopies:NO];
[printController setShowsPageRange:NO];
NSMutableArray * printItems = [NSMutableArray arrayWithCapacity:1];
NSArray * orig = [files copyArray];
for(id file in orig) {
NSURL *baseURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"file:///%@", file]];
NSLog(@"Will print: %@", baseURL.absoluteString);
[printItems addObject:baseURL];
}
[printController setPrintingItems:printItems];
[printController presentAnimated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error2) {
}];
}
@}
}
And this is called from JS using PrintManager.print(["array_of_files"]);
.
I have verified that the images I’m trying to print are valid.
When this code is run, the UX becomes unresponsive (on an iPhone) until I click on the top left - (which is where the “Cancel” button is).