QuickBlox / quickblox-ios-sdk

QuickBlox iOS SDK for messaging and video calling
https://quickblox.com/developers/IOS
MIT License
397 stars 358 forks source link

Could not "createSubscription" on iOS device for new User. #603

Closed williamtran1988 closed 7 years ago

williamtran1988 commented 8 years ago

Hi Everybody,

I have an issue that i could not create a new subscription for new User in existed device, But i could do this with Android device.

Somebody can help me?

ghost commented 8 years ago

Hello, @williamtran1988 We can't help you until you specify:

  1. SDK Version.
  2. Logs .
  3. Code snippet for creating subscriptions.
williamtran1988 commented 8 years ago

I am using Quickblox iOS SDK version 2.7.3.

and my script:

NSString *deviceUDID = [info objectForKey:@"deviceUDID"];
NSData *deviceTokenData = [[NSUserDefaults standardUserDefaults]   
    objectForKey:@"deviceTokenData"];

QBMSubscription *subscription = [QBMSubscription subscription];
subscription.notificationChannel = QBMNotificationChannelAPNS;
subscription.deviceUDID = deviceUDID;
subscription.deviceToken = deviceTokenData;

[QBRequest createSubscription:subscription successBlock:^(QBResponse *response, NSArray *objects) {

} errorBlock:^(QBResponse *response) {

}];

I always get success. But Device is registered with other User. I have tried to delete current subscription on my device. Then tried to create new subscription with new User account with this device. But it returned back to first User account. It's strange.

ghost commented 8 years ago

@williamtran1988, Logs will be helpful. Please, enable full logs and attach them here.

phamminhvu commented 8 years ago

Hi everybody,

We are starting to use Quickblox for our application with calling and push notification features. But we have an issues on the push notification. I don't that is the rule of quickblox or an known issues.

I knew that. 1 user can subscribe on multi devices.

My cases here:

I already logged with a user U1 on device D and checked on the admin page on the Subscriptions page and I see a UUID of Device A.

But when I logout the user U1 on device D and try to login with a new user U2 on device D.

My question is: How can I can delete a subscription was exists with a user and register to a new user (I mean, multi users can login and subscribe on a device. I understand we must unregister the old user on the subscription)?

I am looking forward for your response!

Thanks and Best regards, Jason

ghost commented 8 years ago

@phamminhvu Hello, you should use method:

    NSString *deviceIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    [QBRequest unregisterSubscriptionForUniqueDeviceIdentifier:deviceIdentifier successBlock:^(QBResponse *response) {
        //
    } errorBlock:^(QBError *error) {
        //
    }];
phamminhvu commented 8 years ago

@VitaliyGuru Thanks for you support. It could help me so much. But I have a case:

It this case we have the same Device UUID and device Token but difference User

Thanks, Jason

ghost commented 8 years ago

@phamminhvu Have you try these steps in our sample chat?

phamminhvu commented 8 years ago

@VitaliyGuru Yes, there are our steps: Step 1: Login to QB: [[ChatManager instance] logInWithUser:user completion:^(BOOL error) { //code }]

Step 2. Unregister the current device UUID on subscription

[QBRequest unregisterSubscriptionForUniqueDeviceIdentifier:]

Step 3. If unregister is successful then create subscription [QBRequest createSubscription:subscription successBlock:^(QBResponse response, NSArray objects) { //code }]

Step 4. User 1 logout: if([ChatManager.instance isLoggedIn]){ [ChatManager.instance logOut]; }

User2 will be login with the same steps above

ghost commented 7 years ago

Hi @phamminhvu, Any updates?

phamminhvu commented 7 years ago

Still can not update device UUID. @VitaliyGuru: any suggestion for us!

ghost commented 7 years ago

@phamminhvu please provide logs for you case:

If 2 quickblox's user (User 1 and User 2) logged on 1 device. When I try to logout User 1 and relogin with User 2. It always show the Subscription User 1. I already unregister Subscription with UUID for USER 1 before register create subscription for User 2

williamtran1988 commented 7 years ago

Any updates? The problem still appear in latest version 3.0.

We DID unregisterSubscriptionForUniqueDeviceIdentifier when User logged out. Then login with other USer (User2). But subscription is always User1.

Do you have any ideas?

soulfly commented 7 years ago

Hi @williamtran1988,

It may be because of these 2 lines:

NSString *deviceUDID = [info objectForKey:@"deviceUDID"];
NSData *deviceTokenData = [[NSUserDefaults standardUserDefaults]   
objectForKey:@"deviceTokenData"];

As Apple wrote, you should not cache deviceToken, it's prohibited

The right way to subscribe is:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *deviceIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

    QBMSubscription *subscription = [QBMSubscription subscription];
    subscription.notificationChannel = QBMNotificationChannelAPNS;
    subscription.deviceUDID = deviceIdentifier;
    subscription.deviceToken = deviceToken;

    [QBRequest createSubscription:subscription successBlock:^(QBResponse *response, NSArray *objects) {

    } errorBlock:^(QBResponse *response) {

    }];
}

could you make sure that you have the same in your app?

williamtran1988 commented 7 years ago

Yes, we are using this device id too: NSString *deviceIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

But the problem still the same.

Finally, i found out the what is it now. If you did not delete user when you logged out from application, You will not create a new subscription for new user in 1 device.

soulfly commented 7 years ago

But what about this line?

NSData *deviceTokenData = [[NSUserDefaults standardUserDefaults]   
objectForKey:@"deviceTokenData"];
williamtran1988 commented 7 years ago

Which one is device token which i received from:

Delete user and create new subscript for new user could be a solution. But do you know why i could not use this method:

deleteUserWithID:successBlock:errorBlock:

Which i referred from : https://sdk.quickblox.com/ios/documentation/Classes/QBRequest.html#//api/name/deleteUserWithID:successBlock:errorBlock:

Raikerian commented 7 years ago

@williamtran1988 were you able to fix this?

Raikerian commented 7 years ago

Closing due to lack of the response from issue creator. If the issue is still there for you, I recommend you to create a new issue. As this is not reproducible in any of our sample nor in our app Q-municate, I recommend you to attach some sample project with issue been reproducible next time.