iOS原生SDK经常会迭代更新方法,过时的方法在未来将会被淘汰,另外为兼容老的版本号,以存储图片视频资源到相册为例,在调用前,应根据校验的系统版本号选择最佳方法调用,以保证最优存储代码,核心代码如下:
1.存储图片到相册:
if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions * options = [[PHAssetResourceCreationOptions alloc] init];
[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];
} completionHandler:nil];
}
else {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:nil];
}
2.存储视频到相册:
if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions * options = [[PHAssetResourceCreationOptions alloc] init];
[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypeVideo fileURL:videoURL options:options];} completionHandler:nil];
}
else {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:videoURL completionBlock:nil];
}
网友评论