2011-02-17 27 views
0

我正在開發一個通用應用程序,它是使用SDK 4.2構建的,並且預計可以在3.1到4.2設備上工作。 UIPopOverController用於我的代碼。 iphone和ipad都很少見的參考文獻。有沒有辦法讓ios 3.1說服,3.1到4.2通用問題

「不要包含這個xyz.h如果它是3.1設備」。有沒有使3.1的預處理器。 os接受這個聲明?

回答

2

編譯器不針對每個設備版本編譯應用程序。所以你不能僅僅爲3.1設備「排除」xyz.h。但是,您可以檢查課程是否可用。

Class popoverClass = NSClassFromString(@"UIPopoverController"); 
if(popoverClass) { 
    // class is available 
    UIPopoverController *popover = ... 
} 
else { 
    // use alternate method 
    [self presentModalViewController:vc animated:YES]; 
} 

,或者你可以將不同的邏輯,iPhone或iPad

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    // do something that will only be done on ipad 
} 
else { 
    // do something that will only be done on iphone 
} 

,如果你想要使用一般可在較低的固件版本類,但具體的方法可能是不可用的,你必須檢查前使用它們。

NSURL *fileURL = nil; 
if ([NSURL respondsToSelector:@selector(fileURLWithPathComponents:)]) { 
    fileURL = [NSURL fileURLWithPathComponents:...]; 
} 
else { 
    /* another method to create fileURL */ 
    fileURL = ...; 
} 

請注意,所有這些都是在運行時發生的。

0

鏈接3.1中不存在的符號並沒有什麼壞處。您的目標是確保在3.1設備上的執行流程中不會引用這些符號。

+0

雅,但問題是這些頭文件是共同的iPad和iPhone。所以我有更少的使用選擇,在那xyz.h :( – thndrkiss 2011-02-17 13:46:33