When your app is disconnected from the Stringee server, you cannot receive real-time updates. In this case, you can use Stringee Push Notification to keep your app's data updated.
Check iOS Push Notification to see how to set up Push Notification with Stringee.
Stringee uses Remote Push notification to send push notifications to devices for chat. You need to do the following steps:
Call the following function in didFinishLaunchingWithOptions function to register device for receiving remote push notification from APNS:
- (void)remotePushRegistration {
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
NSLog(@"XIN QUYEN REMOTE PUSH %d", (int)granted);
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
Send your device token to the Stringee server as follows:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *token = [self stringFromDeviceToken:deviceToken];
NSLog(@"**************** Token - Remote push: %@", token);
[[StringeeImplement instance].stringeeClient registerPushForDeviceToken:token isProduction:false isVoip:false completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"======= REGISTER REMOTE PUSH: %@", message);
}];
}
- (NSString *)stringFromDeviceToken:(NSData *)deviceToken {
NSUInteger length = deviceToken.length;
if (length == 0) {
return nil;
}
const unsigned char *buffer = deviceToken.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(length * 2)];
for (int i = 0; i < length; ++i) {
[hexString appendFormat:@"%02x", buffer[i]];
}
return [hexString copy];
}
If things go successfully, you will receive remote push notifications for chat. Stringee push notification data has the following format:
{
data = {
map = {
data = {
map = {
avatarUrl = "";
convId = "conv-vn-1-OZQMBPBUWM-1553965638358";
convName = Demo;
createdTime = 1554261740264;
displayName = hoangnam;
from = user1;
isGroup = 0;
message = {
map = {
content = Alo;
metadata = {
map = {};
};
};
};
msgId = "msg-vn-1-OZQMBPBUWM-1553965654245";
seq = 2;
type = 1;
};
};
stringeePushNotification = "1.0";
type = "CHAT_EVENT";
};
};
}