我们正在使用Xamarin的Azure Messaging组件注册模板推送通知.到目前为止,我们已使用以下模板注册通知:
@"{""aps"": {""alert"": ""$(message)"",""badge"": ""$(badge)"",""sound"": ""$(sound)""}}"
Run Code Online (Sandbox Code Playgroud)
我们将此字符串传递给Hub.RegisterTemplateAsync
iOS应用程序.
从一段时间以前(不到一个月),调用RegisterTemplateAsync
生成以下响应:
Apr 3 13:35:03 iPhone MyApp[352] <Warning>: Error Response:<Error><Code>400</Code><Detail>The supplied notification payload is invalid.TrackingId:5dbf4199-cf52-4245-b8e4-acfa4e00cfee_G7,TimeStamp:4/3/2016 10:35:04 AM</Detail></Error>
Apr 3 13:35:03 iPhone MyApp[352] <Warning>: -------------> Notifications: RegisterTemplateAsync error: Fail to perform registration operation. Response:<Error><Code>400</Code><Detail>The supplied notification payload is invalid.TrackingId:5dbf4199-cf52-4245-b8e4-acfa4e00cfee_G7,TimeStamp:4/3/2016 10:35:04 AM</Detail></Error>
Run Code Online (Sandbox Code Playgroud)
它与以前的二进制文件完全相同.现在它没有.
在解决问题时,我们发现问题在于该badge
字段.当我们删除它时,注册到通知中心成功:
@"{""aps"": {""alert"": ""$(message)"",""sound"": ""$(sound)""}}";
Run Code Online (Sandbox Code Playgroud)
所以现在我们在AppStore中有一个破碎的生产应用程序,无法再收到通知.
这是在集线器方面发生了变化,还是有可能我们做错了什么?
有人可以给我一个理由,让我在一个推送通知通道上拥有一个registraiontId吗?目的是什么?
我已经阅读了很多有关处理推送通知的文章(我使用过Azure服务),但是我没有找到原因。我知道,频道会随着时间变化,然后我需要在后端的每个设备上更改我的注册ID上的频道。
以下方法似乎正在加载多个注册。为什么?
await HubClient.GetRegistrationsByChannelAsync("<pnsHandle>", 100)
Run Code Online (Sandbox Code Playgroud)
换句话说:渠道和注册之间的主要区别是什么?
我对此有些困惑...谢谢
我想将推送通知发送到iPhone.如果我从Azure通知中心 - 网站发送消息,它工作正常,但我无法从我的c#控制台应用程序发送通知.
我添加了Microsoft.Azure.NotificationHubs - Nuget Package,
var client = NotificationHubClient.CreateClientFromConnectionString ( HUBLISTENACCESS, HUBNAME );
client.SendAppleNativeNotificationAsync ( json ).ContinueWith (
t => {
Console.WriteLine (t.Result );
} );
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
但它引发了一个例外情况"未经授权的401".
我希望有人能提供帮助.关心罗尼
我有一些问题,设置一个控制台应用程序,将推送通知发送到iOS/Android设备.
错误显示如下:
Unhandled Exception: System.AggregateException: One or more errors
occurred. ---System.UnauthorizedAccessException: The remote server
returned an error: (401)
Unauthorized..TrackingId:ea158550-8761-41f8-821d-dbcb88fcce56,TimeStamp:18/07/2016
08:58:21 ---System.Net.WebException: The remote server returned an
error: (401) Unauthorized. at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at
Microsoft.Azure.NotificationHubs.NotificationRequestAsyncResult`1.<GetAsyncSteps>b__3(TAsyncResult
thisPtr, IAsyncResult r) at
Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult
result) --- End of inner exception stack trace ---
Server stack trace:
Exception rethrown at [0]: at
Microsoft.Azure.NotificationHubs.Common.AsyncResult.End[TAsyncResult](IAsyncResult
result) at
Microsoft.Azure.NotificationHubs.NotificationHubManager.EndSendNotification(IAsyncResult
result) at
System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult
iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean
requiresSynchronization) --- End of inner exception stack trace --- …
Run Code Online (Sandbox Code Playgroud) c# azure apple-push-notifications google-cloud-messaging azure-notificationhub
在我成功登录后的应用程序中,我想使用标签注册到 NotificationHub,其中 Tag 是电子邮件地址。
以下场景在 iOS 上运行良好:
MessagingCenter.Subscribe<LoginViewModel, string>(this, MessagesId.RegisterForPush, (s, arg) =>
{
NSSet tags = new NSSet(arg); // create tags if you want
Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
{
if (errorCallback != null)
Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
});
});
Run Code Online (Sandbox Code Playgroud)
但相当于 Android 抛出一个NetworkOnMainThreadException
:
MessagingCenter.Subscribe<LoginViewModel, string>(this, MessagesId.RegisterForPush, (s, arg) =>
{
var tags = new List<string>() { arg };
try
{
var hubRegistration = Hub.Register(registrationId, tags.ToArray());
}
catch (Exception ex)
{
Log.Error(PushHandlerBroadcastReceiver.TAG, ex.Message);
}
});
Run Code Online (Sandbox Code Playgroud)
你知道如何解决这个问题吗?
我有一个从 WNS 接收通知的 C#/UWP 应用程序,我可以使用 Azure 通知中心测试页向其发送原始通知。唯一的问题是我无法向集线器注册设备以在发送模板通知时接收原始通知。这是基本代码:
PushNotificationChannel channel = await PushNotificationChannelManager.
CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString);
TemplateRegistration registration = await hub.
RegisterTemplateAsync(channel.Uri, template, "data", tags);
Run Code Online (Sandbox Code Playgroud)
我想要弄清楚的是我需要什么模板值才能让它将数据作为原始数据传递。这是我在注册时遇到的错误:
The bodyTemplate is not in accepted XML format. The first node of the bodyTemplate should be Badge/Tile/Toast, except wns/raw template, which need to be an valid XML
Run Code Online (Sandbox Code Playgroud)
通过该消息,显然有一个“wns/raw template”选项,但我找不到有关如何注册选项的文档。如果重要的话,原始数据的实际格式是 JSON。
Dave Smits 的帮助中修复了代码:
PushNotificationChannel channel = await PushNotificationChannelManager.
CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString);
WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", …
Run Code Online (Sandbox Code Playgroud) 我无法连接到 Microsoft Azure 通知中心来管理订阅(获取注册和发送通知)。我有一个简单的 C# 控制台工具并执行NotificationHubClient 方法,出现异常:(401) 不允许..TrackingId:****uid_here*****
使用 Fiddler,我收到以下原始错误消息: HTTP/1.1 401 40103:无效的授权令牌签名
我正在使用带有正确连接字符串(完全共享访问)的程序集 Microsoft.Azure.NotificationHubs v2.16.0.0 和 WindowsAzure.ServiceBus v4.0.0。我从 azure 管理门户复制了确切的连接字符串,并且还尝试连接 ServiceBusExplorer,但这是不可能的,并且使用此工具时出现错误:
Receivera:InternalServiceFault
由于内部错误,服务器无法处理请求。有关错误的详细信息,请在服务器上打开 IncludeExceptionDetailInFaults(从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为),以便将异常信息发送回客户端,或者根据 Microsoft .NET Framework 打开跟踪SDK 文档并检查服务器跟踪日志。
有人有这样的烦恼吗?
谢了!
更新:谢谢你们。这是一个连接字符串问题。错误在于 SharedAccessKeyName。当前的默认名称是 DefaultFullSharedAccessSignature,我的初始密钥 RootManageSharedAccessKey 不再起作用。我认为天蓝色可以改变它。它不接受与根密钥的连接...或者它被其他人出于其他原因更改。
我正在使用以下代码,但仍然在线上出现挂起问题:-
var allRegistrations = await hub.GetAllRegistrationsAsync(0);
Run Code Online (Sandbox Code Playgroud)
我的代码是:-
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=XXXXXX.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=XXXXXXXXXXXXX", "My hub name", true);
var allRegistrations = await hub.GetAllRegistrationsAsync(0);
Run Code Online (Sandbox Code Playgroud)
请提供更好的解决方案..
谢谢
从 iOS 13 和 watchOS 6 开始,Apple 要求存在用于推送通知的标头apns-push-type
(此标头的值可以是alert
或background
)。
根据苹果文档:
此标头的值必须准确反映通知负载的内容。如果不匹配,或者所需系统上缺少标头,APN 可能会延迟通知的传递或完全丢弃它。
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/xxxxxx
host = api.sandbox.push.apple.com
authorization = bearer xxx
apns-id = xxx-xxx-xxx
apns-push-type = alert
apns-expiration = 0
apns-priority = 10
apns-topic = com.example.MyApp
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
Run Code Online (Sandbox Code Playgroud)
不幸的是,使用 azure 通知中心我只能定义aps
内容而不能定义标题。
{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": …
Run Code Online (Sandbox Code Playgroud) 我正在尝试按照本教程和本示例在 Xamarin.Forms Android 应用程序上设置推送通知。我的AndroidManifest.xml、FirebaseService.cs和MainActivity.cs与示例基本相同。当我启动 Android 模拟器并从 Azure 通知中心进行测试发送时,我得到:“消息已成功发送,但没有匹配的目标。” 该教程过时了吗?
android push-notification firebase azure-notificationhub xamarin.forms
我已经创建了一个 Azure 通知中心命名空间,我尝试通过输入 API 密钥来配置它的 Google FCM 部分,但是当我这样做时,它给了我这个错误
更新通知中心时出错 {"error":{"code":"BadRequest","message":"Firebase 凭据无效。"}}
我从 google-services.json 文件中添加的密钥
但是,当我从 FCM 控制台发送通知时,我可以发送并接收通知。
任何意见将不胜感激
xamarin.android azure-notificationhub xamarin.forms firebase-cloud-messaging
我正在尝试将通知添加到我的 Azure 移动应用程序(Azure 应用程序服务移动应用程序),并且正在努力让它们与 iOS 一起使用。我已经成功地让他们为 Android 工作。
我已按照在线说明设置 Apple 证书和配置文件:
https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter5/ios/
iOS 应用程序正在向 APNS 注册并收到设备令牌。然后我删除“<”和“>”字符以及空格,并将注册发送到通知中心。
var templates = new JObject
{
["genericMessage"] = new JObject
{
{"body", "{\"aps\":{\"alert\":\"$(message)\"}}"}
}
};
var push = m_MobileServiceClient.GetPush();
await push.RegisterAsync(token, templates);
Run Code Online (Sandbox Code Playgroud)
当我发送第一个推送通知请求时...
var notification = new Dictionary<string, string> { { "message", "Test notification message" } };
await m_Hub.SendTemplateNotificationAsync(notification);
Run Code Online (Sandbox Code Playgroud)
...注册已从通知中心删除。
我已将 Azure 通知中心上的定价层提高到标准,并使用它来查找存储在存储帐户中的跟踪,它显示“InvalidToken”作为来自 APNS 的错误。
我做过/检查过的事情:
我在 Info.plist 中添加了以下内容(并非所有说明都包含此内容,但其他文章建议它是必需的)
<key>aps-environment</key>
<string>development</string> …
Run Code Online (Sandbox Code Playgroud)push-notification xamarin.ios apple-push-notifications azure-mobile-services azure-notificationhub