2012-01-14 29 views
0

我正在使用一個使用AssetsLibrary中的照片和視頻的應用程序,並且我只是試圖一勞永逸地確定是否有任何方法要求用戶訪問位置數據以獲取這些資產的權限。我知道EXIF數據包含GPS信息,這對我來說意義重大。AssetsLibrary:位置服務提示。 Instagram如何避免它?

注意:我已經通過StackOverflow進行了搜索,並且發現了類似的問題,並且我沒有將這篇文章簡單地添加到列表中。我正在具體詢問一個(明顯的)反例。

第一次使用Instagram時,我可以瀏覽我的相冊,選擇照片,編輯它們並共享它們,而不會提示有關位置服務。當我選擇點擊標記爲「啓用地理標記」的按鈕時,系統會提示我。檢查設置標籤,看起來好像我沒有點擊那個按鈕,Instagram甚至不會出現在我的設置的位置服務部分。

我的問題是,Instagram如何擺脫這種情況?有人有主意嗎?我想弄清楚我是否可以以某種方式模仿他們的實現,以便我們的用戶在他們拒絕提示時拒絕他們的相機資產。

回答

5

的解釋很簡單。 Instagram使用UIImagePickerController。 UIImagePickerController在未啓用定位服務的情況下工作,但您不會使用此方法獲取EXIF數據。 UIImagePickerController只能通過UIImagePickerControllerReferenceURL檢索元數據(包括GPS)。 UIImagePickerControllerReferenceURL你必須通過AssetsLibrary方法,它需要再次啓用位置服務。 乾杯,

亨德里克

0

正如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]; 
    } 
}