21、popover横竖屏位置改变解决办法
1、 delegate中 处理
– (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
userImageShow = NO;
if ([popoverController isEqual:myPopover])
{
[myPopover release];
myPopover = nil;
}
}
2、屏幕旋转时重新弹出Popover
if (myPopover)
{
if ((self.interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation ==
UIInterfaceOrientationLandscapeRight))
{
[myPopover presentPopoverFromRect:CGRectMake(10,180, 1, 1)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
else
{
[myPopover presentPopoverFromRect:CGRectMake(20,180, 1, 1)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
}
22、plist各种key值含义
原文:http://www.minroad.com/?p=434
UIRequiresPersistentWiFi 在程序中弹出wifi选择的key(系统设置中需要将wifi提示打开)
UIAppFonts 内嵌字体(http://www.minroad.com/?p=412 有详细介绍)
UIApplicationExitsOnSuspend 程序是否在后台运行,自己在进入后台的时候exit(0)是很傻的办法
UIBackgroundModes 后台运行时的服务,具体看iOS4的后台介绍
UIDeviceFamily array类型(1为iPhone和iPod touch设备,2为iPad)
UIFileSharingEnabled 开启itunes共享document文件夹
UILaunchImageFile 相当于Default.png(更名而已)
UIPrerenderedIcon icon上是否有高光
UIRequiredDeviceCapabilities 设备需要的功能(具体点击这里查看)
UIStatusBarHidden 状态栏隐藏(和程序内的区别是在于显示Default.png已经生效)
UIStatusBarStyle 状态栏类型
UIViewEdgeAntialiasing 是否开启抗锯齿
CFBundleDisplayName app显示名
CFBundleIconFile、CFBundleIconFiles 图标
CFBundleName 与CFBundleDisplayName的区别在于这个是短名,16字符之内
CFBundleVersion 版本
CFBundleURLTypes 自定义url,用于利用url弹回程序
CFBundleLocalizations 本地资源的本地化语言,用于itunes页面左下角显示本地话语种
CFBundleDevelopmentRegion 也是本地化相关,如果用户所在地没有相应的语言资源,则用这个key的value来作为默认
最后附上官方文档,所有的key都有,看英文原版才是正路:)点我进入
转自: http://mobile.51cto.com/iphone-284052.htm
IOS SDK兼容性引导是本文要介绍的内容,主要是基于IOS SDK基础的开发介绍说明如何应用于XCode工程的基于IOS SDK开发的技术。来看详细内容讲解。
1、用(weakly linked)弱连接类、方法和函数来支持在不同版本之间的程序运行
2、弱连接整个框架(framework)
3、为不同的IOS SDK选择不同的编译条件
4、在代码中找出过时API的使用
5、确定在运行时操作系统和框架(framework)的版本
一 、在IOS中使用弱连接类
在工程中使用类的弱连接的时候必须确保这些类在运行时的可用性,要不会引起动态连接的错误。
在IOS4.2以后的版本都是使用NSObject class的方法来检测弱连接在运行时态的可用性,这种简单高效的机制使用了NS_CLASS_AVAILABLE的可用性宏。
检测最近release的framework还不支持NS_CLASS_AVAILABLE的宏
在支持NS_CLASS_AVAILABLE的宏framework的条件编译中,可以如下的使用
如果你在不确保是否已经可以使用类方法的时候你可以使用NSClassFromString 方法来判断,使用方法如下:
二、在方法,函数和符号中使用弱连接
和使用类的弱连接一样,在使用它之前要确保方法函数和符号在运行时的可用性,要不在编译的时候会报错动态连接错误,假设你想使用新版本IOS
SDK的特性但是又想能够运行在低版本的SDK中,那么就要对早期的版本设置相应的开发target,在Object-c中
instancesRespondToSelector:
方法告诉我们所给的方法是否可用,例如:使用availableCaptureModesForCameraDevice:这个方法(在4.0以后才是可
用的),我们可以这样使用它。
1、检查一个Object-c方法的可用性
判断一个弱连接的C函数是否可用,只要判断函数的地址是否返回为NULL,以CGColorCreateGenericCMYK 函数为例,我们可以像以下那样使用。
2、检查C方法的可用性
要检测一个C方法是否可用,比较明确的为地址是否为NULL或零。你不能使用反运算符(!)来否定一个函数的可用性
检测一个 external(extern)常量或一个通知的名字应当比较它的地址(address)–而不是符号的名称, 判断是否为NULL or nil
三、弱连接整个Framework
比如一个在高版本中才出现的Framework,想在低版本使用他的特性。那你就必须弱连接那个使用的Framework,详见官方的图解—(其实就是在添加进去的Framework的 required 改成 optional)
四、条件编译for不同的SDK
如果你不止基于一个IOS SDK编译,你就可能需要为base
sdk使用条件化,可以使用在Availability.h中的定义。这个.h文件存在于系统的文件夹/usr/include的文件夹下,例如想在
Mac OS X v10.5(而不是IOS)中使用函数 CGColorCreateGenericCMYK
使用预处理指令for条件编译
五、寻找出在程序中使用的以过时的实例
在IOS或Mac
OS中有时候API会过时,但是过时不代表着那些就从Library或framework中删除,但是在使用的过程中会报出warning,并且在不远的
将来可能会被Apple从中移除。例如我们在code中使用了过时的函数 HPurge那么就会报出如下
所以我们应当在工程中查找出如下的警告并且修改。
六、确定操作系统和Framework的版本
在运行时检查IOS的版本
在运行时检查Mac OS X用Gestalt function 和 系统版本常量
另外,对于许多的Framework你可以在运行时检查指定Framework的版本。
例如:Application Kit(NSApplication.h)定义了NSAppKitVersionNumber常量—可以用来检查Application Kit Framework的版本
如
所以我们可以像如下使用:
跟以上一样在 NSObjCRuntime.h中用定义了NSFoundationVersionNumber全局常量
小结:详解IOS SDK兼容性引导的内容介绍玩玩了,希望通过本文的学习能对你有所帮助!
原文地址:http://blog.csdn.net/diyagoanyhacker/article/details/6673344
24、NSDate 与 NSString 转换
将字符串 “Fri Nov 11 09:06:27 +0800 2011” 转换成Date:
NSDateFormatter *format = [[NSDateFormatter alloc] init];
NSLocale *enLocale = [[NSLocale alloc] initWithLocaleIdentifier:@”en-US”];
[format setLocale:enLocale];
[enLocale release];
[format setDateFormat:@”EEE MMM dd HH:mm:ss ZZZ yyyy”];
NSDate *dateTime = [format dateFromString:message];
将Date转换成字符串:
NSDate *date = [NSDate date];
NSString * dateString = [format stringFromDate:date];
//字符串转换成NSDate 需要设置NSLocale 否则真机上会失败。
25、数组中存储数据查询
NSMutableDictionary *userDic1 = [NSMutableDictionary dictionaryWithCapacity:10];
NSMutableDictionary *userDic2 = [NSMutableDictionary dictionaryWithCapacity:10];
[userDic1 setValue:@”Li” forKey:@”name”];
[userDic2 setValue:@”Wang” forKey:@”name”];
NSArray *userArray = [NSArray arrayWithObjects:userDic1,userDic2,nil];
NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@”SELF.name contains[cd] %@ “,@”L”];
NSMutableArray *searchArray = [NSMutableArray arrayWithArray:[userArray filteredArrayUsingPredicate:namePredicate]];
NSLog(@”searchArray == %@”,searchArray);
(1)、重写canBecomeFirstResponder方法
– (BOOL)canBecomeFirstResponder{
[super canBecomeFirstResponder];
return YES;
}
(2)、创建自定义UIMenuController
UIMenuItem *share = [[UIMenuItem alloc] initWithTitle:@”分享” action:@selector(share:)];
UIMenuItem *email = [[UIMenuItem alloc] initWithTitle:@”邮件” action:@selector(email:)];
UIMenuItem *print = [[UIMenuItem alloc] initWithTitle:@”打印” action:@selector(print:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:share, email,print, nil]];
[menu setTargetRect:self.frame inView:self.superview];
[menu setMenuVisible:YES animated:YES];
(3)、判断显示哪个menu
– (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
[super canPerformAction:action withSender:sender];
if ( action == @selector(share:) || action == @selector(email:) || action == @selector(print:))
{
return YES;
}
else
{
return NO;
}
}
27、iOS本地推送通知方法
– (void)applicationDidEnterBackground:(UIApplication *)application
{
UIDevice* device = [UIDevice currentDevice];
BOOL backgroundSupported = NO;
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
{
backgroundSupported = device.multitaskingSupported;
}
if (backgroundSupported && _bgTask==UIBackgroundTaskInvalid)
{
UIApplication *app = [UIApplication sharedApplication];
_bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
}];
dispatch_async(dispatch_get_main_queue(), ^{
while (app.applicationState==UIApplicationStateBackground && _bgTask!=UIBackgroundTaskInvalid && [app backgroundTimeRemaining] > 10)
{
[NSThread sleepForTimeInterval:1];
NSLog(@”background task %d left left time %d.”, _bgTask, (int)[app backgroundTimeRemaining]);
if ([app backgroundTimeRemaining] < 580)
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif)
{
localNotif.alertBody = [NSString stringWithString:@”测试本地通知消息,后台提示功能。”];
localNotif.alertAction = NSLocalizedString(@”查看”, nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
[application presentLocalNotificationNow:localNotif];
[localNotif release];
break;
}
}
}
NSLog(@”background task %d finished.”, _bgTask);
[app endBackgroundTask:_bgTask];
_bgTask = UIBackgroundTaskInvalid;
});
}
}
你必须 登录后 才能对文章进行评论!