Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios: add printing, but keep compatibility with ios 3

i'm trying to add printing features to an ios app. while printing itself works fine, and the app works on ios > 4, i haven't figured out yet how to keep the ios 3.1 compatibility...

i guess the issue is this: completionHandler:(UIPrintInteractionCompletionHandler)

A block of type UIPrintInteractionCompletionHandler that you implement to handle the conclusion of the print job (for instance, to reset state) and to handle any errors encountered in printing.

once i add the block:

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
};

the app won't even launch on iOS 3.1 probably because blocks aren't available there.

yes, i made sure that this code won't be run when launched on iOS 3.1...

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.2) && ([UIPrintInteractionController isPrintingAvailable]))

so i wonder if there's a way to have printing support for iOS >4.2, but keeping it to run on iOS 3.1?

maybe there's a way to use a method instead of the "block"? or how would be the correct way to have printing available on supported iOS devices, and remain backwards compatible to iOS 3.1?

like image 753
jra Avatar asked Jan 22 '23 00:01

jra


1 Answers

just add -weak_framework UIKit to the project settings under "Other Linker Flags" and make sure you use conditional code for printing API. Conditional code should check feature availability, not OS version:

    if (NSClassFromString(@"UIPrintInteractionController")){
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    };
}

Set your project target to iOS 3, and you're good to go.

like image 199
Moshe Gottlieb Avatar answered Jan 31 '23 06:01

Moshe Gottlieb