ios:添加打印,但保持与ios 3的兼容性

jra*_*jra 4 printing iphone backwards-compatibility

我正在尝试为ios应用添加打印功能.虽然打印本身工作正常,并且该应用程序适用于ios> 4,我还没有想出如何保持ios 3.1兼容性......

我猜问题是这样的:completionHandler:(UIPrintInteractionCompletionHandler)

您实现的UIPrintInteractionCompletionHandler类型的块,用于处理打印作业的结束(例如,重置状态)并处理打印中遇到的任何错误.

一旦我添加块:

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
};
Run Code Online (Sandbox Code Playgroud)

该应用程序甚至不会在iOS 3.1上启动,可能是因为那里没有块.

是的,我确保在iOS 3.1上启动时不会运行此代码...

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.2) && ([UIPrintInteractionController isPrintingAvailable]))
Run Code Online (Sandbox Code Playgroud)

所以我想知道是否有办法让iOS> 4.2的打印支持,但保持它在iOS 3.1上运行?

也许有办法使用方法而不是"块"?或者如何在支持的iOS设备上提供正确的打印方式,并保持向后兼容iOS 3.1?

Mos*_*ieb 6

只需将-weak_framework UIKit添加到"Other Linker Flags"下的项目设置中,并确保使用条件代码打印API.条件代码应检查功能可用性,而不是OS版本:

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

将您的项目目标设置为iOS 3,您就可以开始了.