【发布时间】:2016-12-17 19:43:12
【问题描述】:
我刚刚使用本指南构建了一个简单的“聊天”应用程序:http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20-and-mvc-5
技术:
服务器: ASP.NET MVC 5 + SignalR 2.0
客户端: HTML5/jQuery 2.0.3
构建应用程序: 科尔多瓦
只要我将它用作常规网络应用程序,我的聊天就会正常工作,但如果我开始使用 cordova 将其编译为应用程序,则什么都不会发生。
1) "ChatHub" [Serverh/C#]
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChatMVC.Hubs{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the addNewMessageToPage method to update clients.
Clients.All.addNewMessageToPage(name, message);
}
}
}
2) 路径中的“index.html”
"VisualStudioPath\Projects\SignalRChatMVC\SignalRChatMVC\native\net.Companyname.Projectname\www"
.
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat - My ASP.NET Application</title>
<link href="/Content/bootstrap.css" rel="stylesheet">
<link href="/Content/site.css" rel="stylesheet">
<script src="/Scripts/modernizr-2.7.2.js"></script>
<script src="/Scripts/jquery-2.1.0.min.js"></script>
</head>
<body>
<div class="app">
<h2>Chat</h2>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
<!--Script references. -->
<!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
<!--Reference the SignalR library. -->
<script src="/Scripts/jquery.signalR-2.0.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<!--SignalR script to update the chat page and send messages.-->
<script>
$(function () {
// Reference the auto-generated proxy for the hub.
var chat = $.connection.chatHub;
<!-- $.connection.hub.url = "http://nightcrawler:1234"; -->
// Create a function that the hub can call back to display messages.
chat.client.addNewMessageToPage = function (name, message) {
// Add the message to the page.
$('#discussion').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
</script>
</div>
<!-- <script type="text/javascript" src="cordova.js"></script> -->
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
3) 在浏览器中调用我的 mashine,例如
"http://{computername}:1234"
工作,我可以在任何浏览器/标签或设备上写消息。
4)现在我开始用cordova编译:
cmd: "{VisualStudioPath}\Projects\SignalRChatMVC\SignalRChatMVC\native\net.{Companyname}.{Projectname}"> cordova build blackberry10
cmd: "{VisualStudioPath}\Projects\SignalRChatMVC\SignalRChatMVC\native\net.{Companyname}.{Projectname}"> cordova run blackberry10
然后只出现主屏幕。
有谁知道如何调试本机应用程序和/或知道为什么它不适用于本机应用程序? 是否可能与黑莓的路径有关,它不在
"{VisualStudioPath}\Projects\SignalRChatMVC\SignalRChatMVC\native\net.{Companyname}.{Projectname}\www"
但在
"{VisualStudioPath}\Projects\SignalRChatMVC\SignalRChatMVC\native\net.oh22.oh22Push\platforms\blackberry10\www"
或者可能是因为没有真正的浏览器能够使用 SignalR?
(应该可以直接在黑莓上调试)
非常感谢
【问题讨论】:
标签: jquery asp.net-mvc cordova signalr