提醒:这里是新特征汇总博文链接:iOS7新特征汇总
上一篇文章(iOS7新特征汇总[03]新特征介绍3)中,笔者介绍了在iOS7中关于程序间的音频(inter-App Audio)、点对点的连接、新增的Framework相关内容。本文将继续介绍iOS7中的新特征,包括:已有Framework的改进、Objective-C和已经过时的API。
注1:本文是关于新特征介绍的最后一篇,随后的博文,以wwdc2013内容为主,欢迎大家关注!
下面我们来看看iOS7中有明显修改的一些framework。如果要查看完整的新接口,请查看iOS 7.0 API Diffs。本部分内容看起来可能稍显枯燥,并且我没有对其做配图,所以读者可以挑选自己感兴趣的部分进行阅读也不妨。
UIKit Framework(UIKit.framework)主要做了如下改进:
1、所有的用户界面控件都做了更新,以与iOS7相适应。
2、UIKit动力可以让开发者模拟现实世界中的一些效果,例如在动画中使用重力行为。
3、Text Kit提供了复杂的文字编辑和显示功能。
4、UIView类新增加了如下内容:
tintColor属性:可以使用一个tint color,并对view和它的subview有影响。关于如何使用tint colors,请看iOS 7 UI Transition Guide。
/*
-tintColor always returns a color. The color returned is the first non-default value in the receiver's superview chain (starting with itself).
If no non-default value is found, a system-defined color is returned.
If this view's -tintAdjustmentMode returns Dimmed, then the color that is returned for -tintColor will automatically be dimmed.
If your view subclass uses tintColor in its rendering, override -tintColorDidChange in order to refresh the rendering if the color changes.
*/
@property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(7_0);
通过view可以创建基于关键帧的动画。同样也可以对view做出改变——特别是阻止任意正在执行的动画。
5、UIViewController类新增了如下内容:
View controller之间的切换(transition)可以自定义、驱动式交互(driven interactively),或者完全根据自己指定的切换方式来替换。
可以通过编程的方式指定View controller的status bar和visibility。系统会根据提供的信息来管理status bar style。当然,在程序的info.plist文件中,设置UIViewControllerBasedStatusBarAppearance键值也是可以的。如下代码是iOS7中新增的几个用来指定status bar的方法
// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.
- (UIStatusBarStyle)preferredStatusBarStyle;
- (BOOL)prefersStatusBarHidden;
// This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.
- (void)setNeedsStatusBarAppearanceUpdate;
6、UIMotionEffect类为运动效果定义了一些基本的行为——定义了一个view如何响应基于设备的运动。
7、Collection view支持UIKit动力(UIKit Dynamic)——这样可以将一些行为对象(behavior object)应用到Collection view的layout attribute中,以对collection view中的item做出相应的动画。
8、UIImage的ImageNamed:方法可以把检索存储在asset目录中的图片,这就提供了一种方法——管理并优化具有多种尺寸和分辨率的资源。
9、UIView和UIScreen提供了一个新的方法:snapshot——返回一个view,可以用来显示程序的内容。
/* Creating snapshots from existing snapshots (as a method to duplicate, crop or create a resizable variant) is supported. In cases where many snapshots are needed, creating a snapshot from a common superview and making subsequent snapshots from it can be more performant.
*/
@interface UIView (UISnapshotting)
- (UIView *)snapshot NS_AVAILABLE_IOS(7_0);
- (UIView *)resizableSnapshotFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(7_0); // Resizable snapshots will default to stretching the center
@end
@interface UIScreen (UISnapshotting)
- (UIView *)snapshot NS_AVAILABLE_IOS(7_0);
@end
10、UIKeyCommand类封装了从外围硬件键盘接收到的键盘事件。这些事件会被分发(delivered)到程序的响应链(responder chain)中以被处理。
11、UIFontDescriptor对象使用一个属性字典来描述字体。通过font descriptor可以与其它平台相互交互。
12、UIFont和UIFontDescriptor类支持动态调整字体大小,这样可以增加程序中文字的易读性——用户可以控制所有程序的字体大小。
13、UIActivity类现在支持新的一些activity类型,包括通过AirDrop发送数据,给内容到Safari阅读列表中,把数据发送到Flickr、Tencent Weibo和Vimeo。
14、UIApplicationDelegate协议新增了处理后台获取数据的操作。
/*! This delegate method offers an opportunity for applications with the "remote-notification" background mode to fetch appropriate new data in response to an incoming remote notification. You should call the fetchCompletionHandler as soon as you're finished performing that operation, so the system can accurately estimate its power and data cost.
This method will be invoked even if the application was launched or resumed because of the remote notification. The respective delegate methods will be invoked first. Note that this behavior is in contrast to application:didReceiveRemoteNotification:, which is not called in those cases, and which will not be invoked if this method is implemented. !*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0);
/// Applications with the "fetch" background mode may be given opportunities to fetch updated content in the background or when it is convenient for the system. This method will be called in these situations. You should call the fetchCompletionHandler as soon as you're finished performing that operation, so the system can accurately estimate its power and data cost.
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0);
// Applications using an NSURLSession with a background configuration may be launched or resumed in the background in order to handle the
// completion of tasks in that session, or to handle authentication. This method will be called with the identifier of the session needing
// attention. Once a session has been created from a configuration object with that identifier, the session's delegate will begin receiving
// callbacks. If such a session has already been created (if the app is being resumed, for instance), then the delegate will start receiving
// callbacks without any action by the application. You should call the completionHandler as soon as you're finished handling the callbacks.
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler NS_AVAILABLE_IOS(7_0);
15、UIKit新增了引导访问模式(guided-access mode)——运行程序自己锁定,以防止被用户修改。这样的功能主要是为一些机构设计的,例如在学校——学生虽然携带了他们的设备,但是需要运行由学校提供的程序。
16、State还原功能运行保存和还原任意的对象。遵循UIStateRestoring协议的对象,当程序被切换到后台(background)时,可以把状态信息保存起来 ,之后程序被启动时,这些状态可以被还原。
17、Table view支持对row或其他元素高度的评估(estimating),这样可以提升Table view的滚动性能。
更多关于UIKit framework的内容,请阅读UIKit Framework Reference。
Store Kit framework(StoreKit.framework)已经迁移到新的订单系统(receipt system),这样一来,开发者可以在自己的设备上验证内购(in-app purchase)。同样也可以在服务器上进行程序购买订单的验证。
更多关于新订单系统的使用,请阅读:Receipt Validation Programming Guide。
Security Framework(Security.framework)现在支持:通过iCloud,可以把密码在用户两台设备间进行同步。通过新的keychain属性((kSecAttrSyncronizable),程序可以为iCloud标记它们的keychain item。
更多相关这个属性的内容,请看该framework的头文件。关于keychain更多信息,请看Keychain Services Programming Guide。
Pass Kit Framework(PassKit.ramework)新增了一些API——针对同时添加多个通行证(pass),通行证文件的格式也做了相应的调整:
更多关于如何在程序中使用Pass Kit的信息,请阅读Passbook Programming Guide。关于通行证文件的格式,请阅读Passbook Package Format Reference。
OpenGL ES做了如下新的扩展:
现在可以在vertex shaders中访问纹理了;通过MAX_VERTEX_TEXTURE_IMAGE_UNITS属性决定你可以访问纹理的准确数目。
在MessageUI framework中,MFMessageComposeViewController现在可以支持将附件添加到信息中。关于新接口内容,可以参看framework头文件。
关于这个framework的类,请阅读Message UI Framework Reference。
在Media Player framework中,MPVolumeView类可以判断用户选择的无线路由(wireless route,例如AirPlay和Bluetooth)是否可用。你也可以判断无线路由当前是否可用。关于新接口信息,请参看framework的头文件。关于Media Player framework涉及到的类,请参看Media Player Framework Reference。
关于Map Kit framework相关修改,笔者已经在这里介绍过:iOS7新特征汇总[02]新特征介绍2
更多相关信息,请查阅Map Kit Framework Reference。
Image I/O Framework(ImageIO.framework)现在提供了获取和设置image metadata的接口。
更多相关接口信息,请看framework的头文件。关于framework类的介绍,请看Image I/O Reference Collection。
iAd framework(iAd.framework)做了如下修改——让广告更好的融入到程序中:
关于新接口请看framework中的头文件。关于framework的介绍,请看Ad Support Framework Reference。
关于Game Kit Framework(GameKit.framework)的改变,已经在这里介绍过:iOS7新特征汇总[02]新特征介绍2
更多相关介绍,请看Game Kit Framework Reference。
Foundation framework(Foundation.framework)主要做了如下改进:
更多关于新的接口,请看framework中 大头文件和Foundation release notes。关于该framework类的介绍,请看Foundation Framework Reference。
Core Telephony framework(CoreTelephony.framework)现在可以获取到设备使用的无线电信息:当前的信号强度、cell ID。由运营商开发的相关程序,同样可以通过预定运营商相关服务,来对他们的程序进行验证。
更多相关信息请看Core Telephony Framework Reference。
Core Motion framework(CoreMotion.framework)现在支持step counting(类似计步器)和运动的跟踪。关于step counting——framework通过检测用户的运动,然后根据运动信息计算出步数(貌似很牛叉的样子,不知道准确度如何了)。由于运动信息是由系统检测的,所以即使当程序没有运行的时候,系统也可以持续的收集step数据。通过这样的功能,framework也能区分出不同的运动类型,例如walking、running或者automobile——这对于导航类程序来说,就可以使用这些数据,直接修改用户的运动类型。
更多相关信息,请看Core Motion Framework Reference。
Core Location framework(CoreLocation.framework)可以通过蓝牙设备来测距。通过测距可以确定附近蓝牙设备的范围,并作出相应的反应。例如,在博物馆的画廊里面,可能有一些蓝牙信号,供参观者通过相关程序显示出画廊的入口和出口。framework还支持推迟位置的更新的通知,直到特定的时间或者用户移动距离超过了最小值。
更多相关信息,请看Core Location Framework Reference。
Core Foundation framework(CoreFoundation.framework)现在支持在派送队列(dispatch queues)中进行流对象的调度。
更多相关信息,请看Core Foundation Framework Reference。
Core Bluetooth framework(CoreBluetooth.framework)做了如下改进:
更多相关信息,请看Core Bluetooth Framework Reference。
AV Foundation framework(AVFoundation.framework)做了如下改进:
另外还有很多信息,笔者就不在这里一一列出,读者可以查阅AV Foundation Framework Reference。
Accelerate framework(Accelerate.framework)做了如下改进:
更多相关信息请看Accelerate Framework Reference。
Objective-C加强了对模块(module)的支持,这样可以加快build时间,以及工程索引的时间。用Xcode 5创建的新工程,默认支持模块,如果是之前的一个工程,必须明确的启动模块的支持:通过修改该工程的Enable Modules设置。
已经过时的API
时不时的,苹果会对一些API增加deprecation 宏,表示在开发中,相关的API不应该继续被使用了。当然,遇到deprecation时,相关api并不是立即就过时了,相反,在一定期限内,苹果会提供相关功能的api,进行过渡。
作为开发者来说,尽量避免在代码中使用过时的api是非常重要的——至少,在新写的代码中不要继续使用过时的api了,另外,对于已有的工程中,如果使用了过时的api,也尽量对代码进行更新。
目前,在iOS7中,过时的api有如下一些:
关于过时API完整的列表,请看iOS 7.0 API Diffs。