2016-09-16 137 views
1

奇怪的問題:激活iPhone拍照動作崩潰我的應用程序

我的用戶通過點擊一個按鈕來拍攝照片啓動iPhone相機。例如。輕觸按鈕,相機打開。直到昨天,下面的代碼工作完全正常(並且仍然在我自己的電話上)。但是,在我們測試組中的其他人的手機上,只要點按相機按鈕,應用程序就會崩潰。任何想法爲什麼?看到我的代碼如下 - 我很難過。 :每個人都在運行iOS 10.

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> { 

}  
    @property (strong, nonatomic) NSMutableArray *photoData; 
    @property (weak, nonatomic) IBOutlet UIImageView *imageView; 

    @end 

ViewController.m

- (IBAction)takePhoto:(id)sender { 

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
    self.imageView.image = chosenImage; 

    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 
+0

請您在發佈有關崩潰的問題時,必須在崩潰中包含完整且準確的錯誤消息,並指出導致崩潰的代碼的確切代碼行。 – rmaddy

+0

@rmaddy我沒有這次的唯一原因是因爲我無法看到崩潰錯誤(令人費解,我知道)。在我的設備上,它運行順暢。但它似乎在其他設備上崩潰(我無法插入到我自己的計算機中)... –

+0

讓用戶向您發送崩潰報告。 – rmaddy

回答

1

如果只在ios10崩潰話,那可就成爲中強制要求的privacy key setting的問題和xcode 8。所以你需要在你的info.plist下面添加key

Privacy - Photo Library Usage Description 

來。它可能會解決你的問題,我想。否則你的代碼是完美的。

你可以參考this answer更多的關鍵和它的描述!

+3

你應該投票結束問題作爲重複,而不是一遍又一遍地重新發布你的答案。 – rmaddy

+0

立即嘗試 - 這個答案是有道理的,因爲它在每個設備上崩潰,但我自己!回報不久:) –

+0

@Brittany但你說每個人都在運行iOS 10.你從來沒有說過你沒有使用iOS 10. – rmaddy