【发布时间】:2015-05-12 02:09:01
【问题描述】:
我们正在使用 Azure 通知中心为 iOS 和 Android 实施推送通知系统。
应用程序每次启动时都会注册。使用 appname_userid 标识的标签为设备注册推送通知。例如Android_1122 其中 1122 是唯一的用户 ID。 iPhone 设备中的同样是 iPhone_1122。 一个用户可以拥有多个设备,其中一条推送消息将被发送到具有相同标签的所有设备。
但是,我们面临一个问题,即为少数用户提供重复的推送通知。 每次用户卸载并重新安装应用程序时,都会返回一个新令牌。因此,对于给定的标签,会进行多次注册,从而导致向同一设备发送重复推送。
也浏览过类似下面的链接。但是,对于使用创建注册 ID REST API 的确切含义并不完全清楚,该 API 返回一个registrationId 而无需实际创建注册。 azure notification hubs - app uninstall
请提供一些方法来避免同一设备的重复注册。
下面是我们用来注册的代码。
iOS 设备
NSString *mobileServicesURL = @"Endpoint=sb://mobilepushnotificationhub.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=XXXXXXXXXXXXXXXXX=";
SBNotificationHub *hub = [[SBNotificationHub alloc] initWithConnectionString:mobileServicesURL notificationHubPath:@"notificationhubname"];
[hub registerNativeWithDeviceToken:token tags:[NSSet setWithObjects:[NSString stringWithFormat:@"iphoneapp_%@", [self getUserID]], nil] completion:^(NSError* error) {
completion(error);
}];
Android 设备
private void gcmPush() {
NotificationsManager.handleNotifications(this, SENDER_ID, MyHandler.class);
gcm = GoogleCloudMessaging.getInstance(this);
String connectionString = "Endpoint=sb://mobilepushnotificationhub.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXX=";
hub = new NotificationHub("notificationhubname", connectionString, this);
registerWithNotificationHubs();
// completed Code
}
// Added Method
@SuppressWarnings("unchecked")
private void registerWithNotificationHubs() {
new AsyncTask() {
@Override
protected Object doInBackground(Object... params) {
try {
String regid = gcm.register(SENDER_ID);
Log.e("regid RECEIVED ", regid);
hub.register(regid, "androidapp_" + WhatsOnIndiaConstant.USERId);
WhatsOnIndiaConstant.notificationHub = hub;
WhatsOnIndiaConstant.gcmHub = gcm;
} catch (Exception ee) {
Log.e("Exception ", ee.getMessage().toString());
return ee;
}
return null;
}
}.execute(null, null, null);
}
【问题讨论】:
标签: azure apple-push-notifications google-cloud-messaging azure-notificationhub