django-push-notifications
django-push-notifications copied to clipboard
Support multiple users sharing the same Apple device
Currently the APNSDevice.registration_id
is unique. But the registration_id
provided by Apple is only unique per device, not per user of that device. This prevents two users who share a device both registering that device for notifications.
I had same issue with tastypie resource especially with social auth enabled, but Sending more than two notifications to same device can cause another problem as well in my database based server notification system,
so I filter, update, or create field using unique registration_id field.
Although it is not so efficient, It works. ^^; even in multiple user id cases.
def obj_create(self, bundle, **kwargs):
if APNSDevice.objects.filter(registration_id=bundle.data['registration_id']).exists():
bundle.obj = APNSDevice.objects.get(registration_id=bundle.data['registration_id'])
bundle.obj.user = bundle.request.user
bundle.obj.name = bundle.data['name']
return self.save(bundle)
else:
return super(MyAPNSDeviceAuthenticatedResource, self).obj_create(bundle, user=bundle.request.user, **kwargs)
@Ian-Foote Did you find a solution to your problem? I may be misreading the iOS documentation but I thought that the registration_id is unique per app per device - not just per device. I can look into adding unique_together across the username and registration_id.
@matthewh What's the status on this now?
This is a duplicate of #216. My PR #375 to address this issue was a little too cavalier for you so we will need to figure out a path forward. The unique constraint on the registration_id needs to go. If we want database level enforcement of constraints we will probably need base models for each device and documentation explaining how users can customize them.