iOS7新特征汇总[04]新特征介绍4

来源:互联网 发布:nodejs高级编程 中文 编辑:程序博客网 时间:2024/06/06 07:35

提醒:这里是新特征汇总博文链接:iOS7新特征汇总

ios-7-logo

小引

上一篇文章(iOS7新特征汇总[03]新特征介绍3)中,笔者介绍了在iOS7中关于程序间的音频(inter-App Audio)、点对点的连接、新增的Framework相关内容。本文将继续介绍iOS7中的新特征,包括:已有Framework的改进、Objective-C和已经过时的API。

注1:本文是关于新特征介绍的最后一篇,随后的博文,以wwdc2013内容为主,欢迎大家关注!

已有Framework的改进(19个)

下面我们来看看iOS7中有明显修改的一些framework。如果要查看完整的新接口,请查看iOS 7.0 API Diffs。本部分内容看起来可能稍显枯燥,并且我没有对其做配图,所以读者可以挑选自己感兴趣的部分进行阅读也不妨。

  • UIKit Framework

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

Store Kit framework(StoreKit.framework)已经迁移到新的订单系统(receipt system),这样一来,开发者可以在自己的设备上验证内购(in-app purchase)。同样也可以在服务器上进行程序购买订单的验证。
更多关于新订单系统的使用,请阅读:Receipt Validation Programming Guide。

  • Security Framework

Security Framework(Security.framework)现在支持:通过iCloud,可以把密码在用户两台设备间进行同步。通过新的keychain属性((kSecAttrSyncronizable),程序可以为iCloud标记它们的keychain item。
更多相关这个属性的内容,请看该framework的头文件。关于keychain更多信息,请看Keychain Services Programming Guide。

  • Pass Kit Framework

Pass Kit Framework(PassKit.ramework)新增了一些API——针对同时添加多个通行证(pass),通行证文件的格式也做了相应的调整:

  1. 新的key指定通行证的截止日期
  2. 可以指定通行证只与特定的蓝牙信号相关
  3. 利用新的属性来控制通行证的显示。可以把通行证进行归类,并在通行证的背面显示自定义的文字内容,以及控制显示在通行证上的时间值
  4. 可以给通行证附带一些额外的数据信息,在程序中可以使用这些数据,不过并直接显示给用户
  5. 可以指定那些data detector用于通行证的字段中

更多关于如何在程序中使用Pass Kit的信息,请阅读Passbook Programming Guide。关于通行证文件的格式,请阅读Passbook Package Format Reference。

  • OpenGL ES

OpenGL ES做了如下新的扩展:

  1. EXT_SRGB支持sRBG帧缓冲区(framebuffer)操作
  2. GL_APPLE_pvrtc_sRGB支持将sRGB纹理数据压缩为PVRTC纹理格式
  3. GL_APPLE_draw_instancedGL_APPLE_draw_arrays可以提升渲染的速度->当程序在绘制多个相同的实例对象时。

现在可以在vertex shaders中访问纹理了;通过MAX_VERTEX_TEXTURE_IMAGE_UNITS属性决定你可以访问纹理的准确数目。

  • MessageUI Framework

在MessageUI framework中,MFMessageComposeViewController现在可以支持将附件添加到信息中。关于新接口内容,可以参看framework头文件。

关于这个framework的类,请阅读Message UI Framework Reference。

  • Media Player Framework

在Media Player framework中,MPVolumeView类可以判断用户选择的无线路由(wireless route,例如AirPlay和Bluetooth)是否可用。你也可以判断无线路由当前是否可用。关于新接口信息,请参看framework的头文件。关于Media Player framework涉及到的类,请参看Media Player Framework Reference。

  • Map Kit Framework

关于Map Kit framework相关修改,笔者已经在这里介绍过:iOS7新特征汇总[02]新特征介绍2

更多相关信息,请查阅Map Kit Framework Reference。

  • Image I/O Framework

Image I/O Framework(ImageIO.framework)现在提供了获取和设置image metadata的接口。

更多相关接口信息,请看framework的头文件。关于framework类的介绍,请看Image I/O Reference Collection。

  • iAd Framework

iAd framework(iAd.framework)做了如下修改——让广告更好的融入到程序中:

  1. MPMoviePlayerController类中的新方法可以让你在播放电影之前运行广告
  2. framework对UIViewController进行了扩展,让其更容易创建广告内容。现在,你可以对view controller进行适当的配置——在实际内容显示之前先显示出广告内容。

关于新接口请看framework中的头文件。关于framework的介绍,请看Ad Support Framework Reference。

  • Game Kit Framework

关于Game Kit Framework(GameKit.framework)的改变,已经在这里介绍过:iOS7新特征汇总[02]新特征介绍2

更多相关介绍,请看Game Kit Framework Reference。

  • Foundation Framework

Foundation framework(Foundation.framework)主要做了如下改进:

  1. NSURLSession类是一个新增的类,主要用于程序在后台运行时,对网络资源的操作。这个类替换了NSURLConnection和相关delegate;同样也替换了NSURLDownload和相关delegate。
  2. NSURLComponents类也是一个新增类——用来解析URL的构建。这个类在解析URL的时候支持URI标准(rfc3986/STD66)。
  3. NSNetServiceNSNetServiceBrowser用于在蓝牙和Wi-Fi中点对点的查找。
  4. NSURLCredentialNSURLCredentialStorage两个类可以用来创建同步策略的证书,并可以从iCloud中移除相关同步策略证书。
  5. NSURLCacheNSURLCredentialStorageNSHTTPCookieStorage三个类支持存储请求的异步处理。
  6. NSCalendar类支持新的日历类型。

更多关于新的接口,请看framework中 大头文件和Foundation release notes。关于该framework类的介绍,请看Foundation Framework Reference。

  • Core Telephony Framework

Core Telephony framework(CoreTelephony.framework)现在可以获取到设备使用的无线电信息:当前的信号强度、cell ID。由运营商开发的相关程序,同样可以通过预定运营商相关服务,来对他们的程序进行验证。

更多相关信息请看Core Telephony Framework Reference。

  • Core Motion Framework

Core Motion framework(CoreMotion.framework)现在支持step counting(类似计步器)和运动的跟踪。关于step counting——framework通过检测用户的运动,然后根据运动信息计算出步数(貌似很牛叉的样子,不知道准确度如何了)。由于运动信息是由系统检测的,所以即使当程序没有运行的时候,系统也可以持续的收集step数据。通过这样的功能,framework也能区分出不同的运动类型,例如walking、running或者automobile——这对于导航类程序来说,就可以使用这些数据,直接修改用户的运动类型。

更多相关信息,请看Core Motion Framework Reference。

  • Core Location Framework

Core Location framework(CoreLocation.framework)可以通过蓝牙设备来测距。通过测距可以确定附近蓝牙设备的范围,并作出相应的反应。例如,在博物馆的画廊里面,可能有一些蓝牙信号,供参观者通过相关程序显示出画廊的入口和出口。framework还支持推迟位置的更新的通知,直到特定的时间或者用户移动距离超过了最小值。

更多相关信息,请看Core Location Framework Reference。

  • Core Foundation Framework

Core Foundation framework(CoreFoundation.framework)现在支持在派送队列(dispatch queues)中进行流对象的调度。

更多相关信息,请看Core Foundation Framework Reference。

  • Core Bluetooth Framework

Core Bluetooth framework(CoreBluetooth.framework)做了如下改进:

  1. 该framework现在可以把CBCentralCBPeripheral对象的状态信息进行保存,并且在程序启动的时候还原——这个功能可以支持相关蓝牙设备的长期行为。
  2. CBCentral和CBPeripheral类现在使用NSUUID对象来存储唯一标示。
  3. 现在可以从CBCentralManager中同步的获取一个CBPeripheral对象。

更多相关信息,请看Core Bluetooth Framework Reference。

  • AV Foundation Framework

AV Foundation framework(AVFoundation.framework)做了如下改进:

  • AVAudioSession支持一些新的行为:可以选择音频输入的首选项,包括来自内置麦克风的音频;支持多通道的输入和输出
  • AVVideoCompositing和相关的类支持自定义视频合成器(video compositor)
  • AVSpeechSynthesizer和相关的类提供了语音合成功能
  • capture类新增支持的功能有:查找camaera支持的格式、支持60fps录制、在录制和预览的时候,Video的放大(真实和数字化)、实时查找机器可读的条形码数据、自动对焦范围的限制、采集录制过程中访问时钟。

另外还有很多信息,笔者就不在这里一一列出,读者可以查阅AV Foundation Framework Reference。

  • Accelerate Framework

Accelerate framework(Accelerate.framework)做了如下改进:

  1. 支持Core Graphics数据类型的操作
  2. 支持灰度图片:每个像素为1、2或4位
  3. 可以在不同图像格式之间进行转换
  4. 支持biguad(IIR)操作

更多相关信息请看Accelerate Framework Reference。

Objective-C

Objective-C加强了对模块(module)的支持,这样可以加快build时间,以及工程索引的时间。用Xcode 5创建的新工程,默认支持模块,如果是之前的一个工程,必须明确的启动模块的支持:通过修改该工程的Enable Modules设置。

已经过时的API

时不时的,苹果会对一些API增加deprecation 宏,表示在开发中,相关的API不应该继续被使用了。当然,遇到deprecation时,相关api并不是立即就过时了,相反,在一定期限内,苹果会提供相关功能的api,进行过渡。

作为开发者来说,尽量避免在代码中使用过时的api是非常重要的——至少,在新写的代码中不要继续使用过时的api了,另外,对于已有的工程中,如果使用了过时的api,也尽量对代码进行更新。

目前,在iOS7中,过时的api有如下一些:

  1. Map Kit framework中的MKOverlayView和它相关的子类都已经过时了。并且使用MKOverlayRenderer类来代替。更多相关资料,请看Map Kit Framework Reference。
  2. 在Audio Toolbox framework中的AudioSession API已经过时了。程序中应该使用AV Foundation framework中的AVAudioSession类来代替。
  3. 在Core Location framework中的CLRegion类已经被CLCircularRegion类取代了。只不过CLRegion类还继续存在着——当做一个抽象的基类——以对geographic和beacon region的支持。
  4. CBCentral中的属性UUID已经过时了。现在使用identifier属性来对central对象进行唯一标示。
  5. Game Kit framework中也有一些过时的api,主要是为了新功能提供更好的支持。相关信息请看上面提到的参考资料。
  6. UIKit中有如下一些过时的内容:UIViewControllerwantsFullScreenLayout属性已经过时。在iOS7以及之后的版本中,view controller一直都是全屏布局;UIPopovercontroller类不再支持箭头朝向的概念;现在支持内容呈现(presentation)朝向。UIColor对象提供的背景纹理已经不存在了。NSString中的许多功能已经过时,建议使用新的功能。
  7. libsyscall库中的gethostuuid方法已经过时。
  8. iOS7以及之后的版本中,如果请求获取iOS设备的MAC地址,系统会返回02:00:00:00:00:00。如果需要唯一标示设备,使用UIDevice的identifierForVendor属性代替。(在程序中,如果需要自己的广告标示符,那么应该考虑使用ASIdentifierManager的advertisingIdentifier属性替代。)

关于过时API完整的列表,请看iOS 7.0 API Diffs。

原创粉丝点击