如果iOS5可用,我如何检查并有条件地编译/运行代码?
我正在使用Appirater(https://github.com/arashpayan/appirater)在我的xcode项目中启用应用程序评级.使用"iOS模拟器"时,一切都建立正常,但当我使用"iOS设备"目标存档我的项目时,我得到2个构建错误:
语义问题:函数'SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO'的隐式声明在C99中无效
语义问题:函数'SYSTEM_VERSION_LESS_THAN'的隐式声明在C99中无效
相关的代码行位于Appirater.m文件中:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") && SYSTEM_VERSION_LESS_THAN(@"7.1")) {
reviewURL = [templateReviewURLiOS7 stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%@", _appId]];
}
Run Code Online (Sandbox Code Playgroud)
任何援助将不胜感激.
#define A7VERSION() ({[[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];})
#define IS_OS_7 A7VERSION()>=7
Run Code Online (Sandbox Code Playgroud)
上述声明似乎编译得很好.
但是只要我添加一个.m文件,我就会得到以下异常"在预处理程序表达式启动时出现无效令牌".我无法理解我错在哪里
@implementation AppViewController
#if IS_OS_7
….
#else
….
#endif
@end
Run Code Online (Sandbox Code Playgroud) 在iOS6中,我使用此代码来创建我的UIBarButtonItem:
UIBarButtonItem* validate = [[UIBarButtonItem alloc]initWithTitle:@"MyTitle" style:UIBarButtonItemStylePlain target:self action:@selector(actionValidate)];
[validate setTintColor:[UIColor orangeColor]];
self.navigationItem.rightBarButtonItem = validate;
Run Code Online (Sandbox Code Playgroud)
它在iOS6中运行良好,但在iOS7中,按钮的颜色只有在你推动时才会改变.我该如何解决这个问题?
如何仅针对iOS 5兼容性的iOS 5执行代码?我写了这段代码:
BOOL isIOS5 = [[[UIDevice currentDevice] systemVersion] floatValue] > 4.3;
if (isIOS5) {
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"cabecera.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setTintColor:[UIColor colorWithRed:80.0f/255.0f green:150.0f/255.0f blue:185.0f/255.0f alpha:1]];
}
Run Code Online (Sandbox Code Playgroud)
如果我在iOS 5中执行该应用程序它工作正常,但如果我尝试在iOS <5模拟器中执行该应用程序,它会中断.有没有办法编写一个只有iOS5代码但在iOS <5时忽略它的应用程序?
显然,我使用Twitter oAuth(令牌请求)在iOS 5中不起作用...如何在iOS 5以下的任何地方保留此代码并使用适用于iOS 5+的新Twitter框架?
是否可以检测iOS版本?
谢谢!
有没有办法测试Objective-C中C函数的存在?我正在寻找像"respondsToSelector"这样的东西,但是对于C函数.
更具体地说,我正试图在iOS中测试"UIGraphicsBeginImageContextWithOptions(CGSize size,BOOL opaque>,CGFloat scale)"的存在.
谢谢.
我正在使用以下方法来更改tabbar图标颜色,
[tabBarController.tabBar setSelectedImageTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
但在使用它之前,我读了一些关于苹果应用程序拒绝的帖子,因为这个问题.我假设现在必须接受ios5方法.这是真的吗?谢谢.
我是iOS开发的新手,我一直想知道在iOS 4上运行我的应用程序的用户是否尝试运行此代码:
//POST TWEET//
- (void)showTweetSheet
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
switch(result) {
case TWTweetComposeViewControllerResultCancelled:
break;
case TWTweetComposeViewControllerResultDone:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Tweet Sheet has been dismissed.");
}];
});
};
[tweetSheet setInitialText:@"Check out this cool picture I found on @Pickr_"];
// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:ImageHost]]){
NSLog(@"Unable to add the URL!");
}
[self presentViewController:tweetSheet animated:YES completion:^{
NSLog(@"Tweet sheet has been …Run Code Online (Sandbox Code Playgroud) 有时在新版本的iOS中添加了一些很容易使用的功能,但是您不希望仅仅因为一个次要功能而阻止旧设备上的用户使用该应用程序.
我刚刚添加UIRefreshControl到iOS 6中添加的应用程序.我真的不在乎使用第三方解决方案(其中有一个数字),我只是不想调用设置的代码如果我在旧设备上运行它.我怀疑,作为一种静态语言,这是不可能的,但我想我会问,看看是否有办法实现这一目标.
显然,如果我只是共享代码,我可以使用预处理器宏来完成,但我需要构建应用程序以在iOS 5.1 + iOS 6.0上执行.
可能重复:
检查iPhone iOS版本
我正在构建一个具有SMS编写器的应用程序(在3.0中不可用).如何动态查找底层设备的操作系统版本并使SMS选项可用,如果不能禁用该功能.
我正在编写Xcode 8.0中的objective-c代码,用于我正在使用的API可用性
if (@available(iOS 11, *)) {
// iOS 11 (or newer) ObjC code
} else {
// iOS 10 or older code
}
Run Code Online (Sandbox Code Playgroud)
不幸的是编译器触发:
无法识别的平台名称iOS
为什么?