[英]Phone Hangs after taking Photo in xamarin.forms
所以我一直在研究 xamarin.forms 移動應用程序,其中一部分涉及拍照,它一直工作正常,但昨天手機在拍照后突然掛起,當時沒有新的代碼更改。
這是一個 xamarin.forms 項目,僅針對 android,在 pie 9.0 API 28 上運行 VS2019 內置模擬器
我花了很多時間試圖解決這個問題,但我對移動開發很陌生,我不知道是什么原因,似乎有些東西正在用新的分配淹沒托兒所 memory 但我不能一旦圖像被拍攝並接受,控制台就會開始泛濫:
11-07 10:08:21.691 I/.co.lilleker_i(16426): Explicit concurrent copying GC freed 8770(448KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1623KB/3MB, paused 617us total 5.821ms
11-07 10:08:21.695 D/Mono (16426): GC_TAR_BRIDGE bridges 1439 objects 1439 opaque 0 colors 1439 colors-bridged 1439 colors-visible 1439 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.04ms tarjan 0.20ms scc-setup 0.14ms gather-xref 0.15ms xref-setup 0.02ms cleanup 0.06ms
11-07 10:08:21.695 D/Mono (16426): GC_BRIDGE: Complete, was running for 15.62ms
11-07 10:08:21.695 D/Mono (16426): GC_MINOR: (Nursery full) time 3.80ms, stw 4.91ms promoted 158K major size: 1680K in use: 912K los size: 1024K in use: 208K
這種情況每半秒發生一次,並且應用程序變得無響應,我已禁用在此之后運行的所有其他代碼,因此運行以下方法:
private async Task<Byte[]> GetPhoto()
{
try
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ": (No Camera available.", "OK");
return null;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return null;
await DisplayAlert("File Location", file.Path, "OK");
return null;
}
catch(Exception ex)
{
string m = ex.Message;
return null;
}
}
警報與路徑一起顯示,但之后它掛起(我什至無法關閉警報)
我在日志中發現的唯一可能存在問題的是以下行:
type=1400 audit(0.0:1494): avc: denied { link } for comm=54687265616420506F6F6C20576F72 name="PropertyStore.forms.tmp" dev="dm-1" ino=123214 scontext=u:r:untrusted_app:s0:c96,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c96,c256,c512,c768 tclass=file permissive=0
但我似乎無法找出這實際上意味着什么。 任何幫助將非常感激。
好的,所以在被問到一個示例項目后,我創建了一個新項目並使用了確切的代碼,卻發現它突然沒有這個問題。 我花了一些時間試圖看看有什么不同,只是注意到新創建的項目已經更新了 xamarin.forms 和 xamarin.essentials 包。
After a lot of fudging with nuget i managed to get my application upgraded to use Xamarin.Essentials 1.2.0 and Xamarin.Forms 4.2.0.709249 (which is the same as the new project template uses) and the issue is now resolved.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.