django-push-notifications icon indicating copy to clipboard operation
django-push-notifications copied to clipboard

Support multiple users sharing the same Apple device

Open LilyFoote opened this issue 9 years ago • 4 comments

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.

LilyFoote avatar Jul 08 '15 16:07 LilyFoote

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)

tub216 avatar Jul 23 '15 01:07 tub216

@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 avatar Oct 07 '15 01:10 matthewh

@matthewh What's the status on this now?

jleclanche avatar Apr 04 '17 15:04 jleclanche

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.

matthewh avatar Apr 04 '17 16:04 matthewh