我在我的应用中使用深层链接,我想在使用var filestream = fs.createReadStream('file.mp3');
var range = request.headers.range.replace("bytes=", "").split('-');
filestream.on('open', function() {
var stats = fs.statSync('file.mp3');
var fileSizeInBytes = stats["size"];
// If the start or end of the range is empty, replace with 0 or filesize respectively
var bytes_start = range[0] ? parseInt(range[0], 10) : 0;
var bytes_end = range[1] ? parseInt(range[1], 10) : fileSizeInBytes;
var chunk_size = bytes_end - bytes_start;
if (chunk_size == fileSizeInBytes) {
// Serve the whole file as before
response.writeHead(200, {
"Accept-Ranges": "bytes",
'Content-Type': 'audio/mpeg',
'Content-Length': fileSizeInBytes});
filestream.pipe(response);
} else {
// HTTP/1.1 206 is the partial content response code
response.writeHead(206, {
"Content-Range": "bytes " + bytes_start + "-" + bytes_end + "/" + fileSizeInBytes,
"Accept-Ranges": "bytes",
'Content-Type': 'audio/mpeg',
'Content-Length': fileSizeInBytes
});
filestream.pipe(response.slice(bytes_start, bytes_end);
}
});
导航到viewmodel时预设一些参数。深层链接网址是这样的:
myappname://深层链接/ toviewwithdata / navigatetoview = viewtype1和ID = 78910
因此,深层链接正在运行,并且使用汇编属性
进入导航外观IMvxNavigationFacade
我尝试使用[assembly: MvxNavigation(typeof(RoutingFacade), @"myappname://deeplink/toviewwithdata/\?navigatetoview=(?<viewtype>viewtype1)&id=(?<id>\d{5})")]
向MvxViewModelRequest
添加其他参数,但不要认为我做得对。这是我的导航立面:
MvxBundle
然后是我的viewmodel Init方法
public class RoutingFacade : IMvxNavigationFacade
{
public Task<MvxViewModelRequest> BuildViewModelRequest(string url, IDictionary<string, string> currentParameters)
{
var viewModelType = typeof(FirstViewModel);
var parameters = new MvxBundle();
try
{
// TODO: Update this to handle different view types and add error handling
if (currentParameters != null)
{
Debug.WriteLine($"RoutingFacade - {currentParameters["viewtype"]}, {currentParameters["id"]}");
switch (currentParameters["viewtype"])
{
case "viewtype1":
viewModelType = typeof(FirstViewModel);
parameters.Data.Add("test", "somevalue");
break;
default:
case "viewtype2":
viewModelType = typeof(FirstViewModel);
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"RoutingFacade - Exception: {ex.Message}");
//TODO viewModelType = typeof(ErrorViewModel);
}
return Task.FromResult(new MvxViewModelRequest(viewModelType, parameters, null));
}
但测试参数为空?如何将参数传递给MvxViewModelRequest?
更新
由于请求参数是从deeplink url的正则表达式设置并且从BuildViewModelRequest返回的,所以不知道是否可以查看源https://github.com/MvvmCross/MvvmCross/blob/f4b2a7241054ac288a391c4c7b7a7342852e1e19/MvvmCross/Core/Core/Navigation/MvxNavigationService.cs#L122,sqRequest.parameterValues会被忽略。