当前位置:网站首页>How to set cloud user information

How to set cloud user information

2020-12-08 10:37:50 osc_ jmtenr3d

Recently, we are using rongyun , Due to first use , There was a small hole , Record it here , Hope to help the follow-up developers

The problem is the use of cloud fusion IMKit Components , That is to bring your own UI Of , For fast trial and error products , The construction period must be short , So use IMKit It's very convenient , It saves a lot of time on the interface . But in the process of using it, we found that , No user's Avatar or nickname . After reading the document, I found that , Need to set up “ User information provider ” Proxy method .SDK When you need to show your avatar and nickname , Through this agent, we will ask the developer for user information , Developers just follow the agent , And implement the proxy method , Return the user information .

Code up :

1. Follow agency

@interface AppDelegate () <RCIMUserInfoDataSource>

@end

2. Setting agent

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // You have to initialize 
    [[RCIM sharedRCIM] initWithAppKey:" Developer's own  appkey"];
    [[RCIM sharedRCIM] connectWithToken:" Current user's  token" dbOpened:^(RCDBErrorCode code) {

        } success:^(NSString *userId) {

        } error:^(RCConnectErrorCode errorCode) {

        }];
    // Set current user information 
    RCUserInfo *currentUser = [[RCUserInfo alloc] initWithUserId:@"tiezhu" name:@" Iron pillar " portrait:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1573646812313&di=116350f184eda99d91393304fa83a6ea&imgtype=0&src=http%3A%2F%2Fimg.jinse.com%2F712431_image3.png"];
    [RCIM sharedRCIM].currentUserInfo = currentUser;
    // Setting agent 
    [RCIM sharedRCIM].userInfoDataSource = self;
}

3. Implementing agent methods

- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *userInfo))completion {
    // It's better to get user information from the developer's own server , Then return . This is just an example 
    RCUserInfo *user = nil;
    if ([userId isEqualToString:@"tiezhu"]) {
        user = [[RCUserInfo alloc] initWithUserId:@"tiezhu" name:@" Iron pillar " portrait:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1570172426&di=01d14daa81f320235376d9c4dede0493&imgtype=jpg&er=1&src=http%3A%2F%2Fgss0.baidu.com%2F-vo3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2Fd788d43f8794a4c240e9466f0ef41bd5ac6e39af.jpg"];
    }
    if (completion) {
        completion(user);
    }
}

That's it, brother , It's worth a cup of milk tea in autumn

版权声明
本文为[osc_ jmtenr3d]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208103709162o.html