1. 添加通訊錄聯系人
/**
添加聯系人
*/
+ (void)addContact:(CNContact *)contact {
// 建立聯系人請求
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest addContact:[contact mutableCopy] toContainerWithIdentifier:nil];
// 寫入聯系人
CNContactStore *store = [[CNContactStore alloc] init];
[store executeSaveRequest:saveRequest error:nil];
}
2. 添加圖檔到圖庫中
let image = UIImage.init(data: successObject as! Data)!
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: image)
}, completionHandler: { (isCompleted, error) in
if error != nil {
myPrint(message: "image save error")
}
})
3. 添加視訊到圖庫中
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: successObject as! URL)
}, completionHandler: { (isCompleted, error) in
if error != nil {
myPrint(message: "video save error")
}
})