设备Id在Xamarin Android中表示Azure推送通知是什么意思?如何得到它?

设备Id在Xamarin Android中表示Azure推送通知是什么意思?如何得到它?,android,ios,azure,xamarin,push-notification,Android,Ios,Azure,Xamarin,Push Notification,我们正在使用Azure移动服务将通知推送到Xamarin Android、Xamarin iOS和Windows Universal应用程序。Windows Universal应用程序有大量关于我们需要的文档,尽管我们还没有机会实现它。然而,XamarinAndroid和iOS都缺少关于推送通知的所有文档。如果您转到并选择Xamarin Android或Xamarin iOS和.NET后端,则这些API的文档链接为零。在昨天挖掘了一吨后,我发现了这个:这两个都是去年9月更新的。文件承诺在5个月前

我们正在使用Azure移动服务将通知推送到Xamarin Android、Xamarin iOS和Windows Universal应用程序。Windows Universal应用程序有大量关于我们需要的文档,尽管我们还没有机会实现它。然而,XamarinAndroid和iOS都缺少关于推送通知的所有文档。如果您转到并选择Xamarin Android或Xamarin iOS和.NET后端,则这些API的文档链接为零。在昨天挖掘了一吨后,我发现了这个:这两个都是去年9月更新的。文件承诺在5个月前更新

当我将Microsoft的Xamarin组件用于Azure移动服务时:我能够启动并运行MobileServiceClient,但不能启动推送通知

API:

Push pushManager = MobileService.GetPush();
string deviceId = "what is this???";
//Option 1:
pushManager.RegisterNativeAsync(deviceId);
//Option 2:
GcmRegistration googleNotificationRegistration = new GcmRegistration(deviceId);
pushManager.RegisterAsync(googleNotificationRegistration);
我正在使用的文档:

  • Push.RegisterAsync:
  • GCMRRegistration:我找不到这个类的任何文档
  • 注册(GCM注册的基类):
    • 注意:用于注册的参数未命名为deviceId,而是命名为channelUri
  • Push.RegisterNativeAsync:
    • 注意:RegisterNativeAsync的参数没有命名为deviceId,而是命名为channelUri
我的问题很简单: 设备ID应该是什么?我如何得到它?

以上所有文档都是针对Winodws通用应用程序的,而不是针对Mono上的Xamarin应用程序

在这个问题的撰写过程中,我发现了一些关于“开始使用通知中心”的文章:

  • 沙马林iOS-
  • 沙马林安卓-
这些是我应该使用的示例吗?它们看起来很老,安卓一号对Azure移动服务只字不提。我甚至不应该在Android上使用Azure移动服务Xamarin组件吗?

tl;dr

deviceId
应该只是
GCMRegistrationId

    @Override
    public void onRegistered(Context context,  final String gcmRegistrationId) {
        super.onRegistered(context, gcmRegistrationId);

        new AsyncTask<Void, Void, Void>() {

            protected Void doInBackground(Void... params) {
                try {
                    ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
                    return null;
                }
                catch(Exception e) { 
                    // handle error             
                }
                return null;            
            }
        }.execute();
    }

我研究了组件DLL和Android SDK实现的源代码

<强>第一< /强>,让我们看一下场景后面的选项1和选项2。基本上,两者最终都会做相同的工作,创建一个

GcmRegistration
,并将其传递给内部
RegistrationManager

    public Task RegisterAsync (Registration registration)
    {
        if (registration == null) {
            throw new ArgumentNullException ("registration");
        }
        if (string.IsNullOrWhiteSpace (registration.PushHandle)) {
            throw new ArgumentNullException ("registration.deviceId");
        }
        return this.RegistrationManager.RegisterAsync (registration);
    }

    public Task RegisterNativeAsync (string deviceId, IEnumerable<string> tags)
    {
        if (string.IsNullOrWhiteSpace (deviceId)) {
            throw new ArgumentNullException ("deviceId");
        }
        GcmRegistration registration = new GcmRegistration (deviceId, tags);
        return this.RegistrationManager.RegisterAsync (registration);
    }
然后我切换到Android移动服务SDK,寻找类似的代码,以找到一些提示。不幸的是,它在android中被称为
pnsHandle
,但仍然没有提示它是什么

    /**
     * Registers the client for native notifications with the specified tags
     * @param pnsHandle PNS specific identifier
     * @param tags  Tags to use in the registration
     * @return  The created registration
     * @throws Exception
     */
    public Registration register(String pnsHandle, String... tags) throws Exception {
        if (isNullOrWhiteSpace(pnsHandle)) {
            throw new IllegalArgumentException("pnsHandle");
        }

        Registration registration = PnsSpecificRegistrationFactory.getInstance().createNativeRegistration(mNotificationHubPath);
        registration.setPNSHandle(pnsHandle);
        registration.setName(Registration.DEFAULT_REGISTRATION_NAME);
        registration.addTags(tags);

        return registerInternal(registration);
    }
最后,我想下面的示例代码应该调用现在解释一切的相同API,即
deviceId
就是
GCMRegistrationId

    @Override
    public void onRegistered(Context context,  final String gcmRegistrationId) {
        super.onRegistered(context, gcmRegistrationId);

        new AsyncTask<Void, Void, Void>() {

            protected Void doInBackground(Void... params) {
                try {
                    ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
                    return null;
                }
                catch(Exception e) { 
                    // handle error             
                }
                return null;            
            }
        }.execute();
    }
@覆盖
public void onRegistered(上下文上下文,最终字符串GCMRRegistrationID){
super.onRegistered(上下文,GCMRRegistrationID);
新建异步任务(){
受保护的Void doInBackground(Void…参数){
试一试{
ToDoActivity.mClient.getPush().register(GCMRRegistrationID,null);
返回null;
}
捕获(例外e){
//处理错误
}
返回null;
}
}.execute();
}

经过多次搜索并直接与MS团队成员交谈后,我同意。这正是deviceId应该是什么。只是不清楚。在苹果方面,它在文档中更有意义。在编写了解决方案和数小时的研究之后,Android方面也有意义,只是不那么清楚。谢谢