[英]AssetsLibrary: Location Services prompt. How did Instagram avoid it?
我正在使用一個使用AssetsLibrary中的照片和視頻的應用程序,而我只是想一勞永逸地確定是否有任何辦法可以要求用戶允許訪問位置數據以獲取這些資產。 我了解EXIF數據包含GPS信息,這對我來說足夠有意義。
注意:我搜索了StackOverflow,發現了類似的問題,我在此發布的目的並非僅僅是在列表中添加一個。 我專門詢問一個(明顯的)反例。
首次使用Instagram時,我可以瀏覽我的相冊,選擇照片,對其進行編輯並共享它們,而無需任何有關位置服務的提示。 僅當我選擇單擊標記為“啟用地理標記”的按鈕時,系統才會提示我。 檢查設置選項卡,好像我從未單擊過該按鈕,Instagram甚至沒有出現在“設置”的“位置服務”部分中。
我的問題是,Instagram如何擺脫這種情況? 有人有想法么? 我想弄清楚我是否可以模仿他們的實現方式,這樣如果我的用戶對此提示說“不”,那么我的用戶就不會被排斥在外。
解釋很簡單。 Instagram使用UIImagePickerController。 UIImagePickerController可以在未啟用定位服務的情況下工作,但是您無法使用此方法獲取EXIF數據。 UIImagePickerController只能通過UIImagePickerControllerReferenceURL檢索元數據(包括GPS)。 您必須先傳遞UIImagePickerControllerReferenceURL,然后再傳遞AssetsLibrary方法,這需要再次啟用位置服務。 干杯,
亨德里克
如holtmann所述,讀取UIImagePickerControllerReferenceURL會觸發位置服務提示。 如果只需要圖像數據,而不是元數據,則可以從UIImagePickerControllerOriginalImage和UIImagePickerControllerEditedImage鍵中獲取(我先檢查EditedImage,然后如果EditedImage為null則檢查OriginalImage)。 這不需要使用資產庫,也不需要位置訪問。
這是我在應用程序中使用它的方式,包括保存圖像的本地副本以供進一步編輯:
- (void)imagePickerController:(UIImagePickerController *)controller didFinishPickingMediaWithInfo:(NSDictionary *)info {
// get the selected photo as a UIImage
UIImage *photo = [info objectForKey:@"UIImagePickerControllerEditedImage"];
if (!photo) {
photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
// save the photo to the app's Documents folder
if (photo) {
NSString *extension = @"jpg";
NSString *filename = [NSString stringWithFormat:@"%@.%@", self.defaultTitle, extension]; // self.defaultTitle is defined elsewhere in my app
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:filename];
[UIImageJPEGRepresentation(photo, 0.8) writeToFile:path atomically:YES];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.