首次安装时,应用程序在调试模式下崩溃

时间:2019-08-27 11:35:22

标签: ios video download xamarin.ios crash

我正在尝试下载视频,然后将其分享到Instagram。

在模拟器中,当我第一次安装该应用程序(删除现有应用程序)并执行与Instagram共享的功能时,该应用程序崩溃。

应用程序第一次显示弹出窗口,要求获得对PHPhotoLibrary的许可。

但是它运行良好,并且可以在运行(已安装)应用程序时共享给Instagram。

在控制台崩溃日志中显示类似 Native Crash sigsegv

Check the crash-log here

public NSUrl DownloadVideoIOS(string url, string folder)
        {
            NSUrl returnPath = null;

            var videoName = url.Substring(url.LastIndexOf('/') + 1);

            if (File.Exists(Path.Combine(NativeVideosPath, videoName)))
                return new NSUrl(Path.Combine(NativeVideosPath, videoName));

            if (File.Exists(Path.Combine(ImagesCachePath, videoName)))
                return new NSUrl(Path.Combine(VideosCachePath, videoName));

            if (Items.ContainsKey(url))
                return ItemsVideos[url];

            using (var urlvideo = new NSUrl(url))
            using (var data = NSData.FromUrl(urlvideo))
            {

                if (!NSFileManager.DefaultManager.FileExists(VideosCachePath))
                    NSFileManager.DefaultManager.CreateDirectory(VideosCachePath, false, null);

                var result = NSFileManager.DefaultManager.CreateFile(Path.Combine(VideosCachePath, videoName), data, new NSFileAttributes());
                if (!result)
                    ItemsVideos[url] = returnPath;

                return returnPath;
            }
        }

var path = DownloadVideosIOS(url, "DownloadedVideos");

            PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {

                PHAssetChangeRequest request = PHAssetChangeRequest.FromVideo(path);
                string id = request.PlaceholderForCreatedAsset.LocalIdentifier;

                var shareURL = "instagram://library?LocalIdentifier=" + id;

                BeginInvokeOnMainThread(() =>
                {
                    //UIApplication.SharedApplication.OpenUrl(new NSUrl(shareURL));
                    if (UIApplication.SharedApplication.CanOpenUrl(new NSUrl(shareURL)))
                    {
                        UIApplication.SharedApplication.OpenUrl(new NSUrl(shareURL));
                        Console.WriteLine("Instagram ShareURL: -> " + new NSUrl(shareURL));
                    }
                    else
                    {
                        Console.WriteLine("(Not Instagram)but ShareURL: -> " + new NSUrl(shareURL));
                    }
                });
            },
            (bool success, NSError error) => {
            });

VideoCachePath:

DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
NativeVideosPath = "ChannelLogos";
VideosCachePath = Path.Combine(DocumentsPath, "ChannelLogos");

0 个答案:

没有答案