2021-06-02
本來項目已經(jīng)集成了rongcloud的sdk,能用可是有些api和ios功能有差距,
發(fā)送本地媒體文件,關閉了通知,
var msc = MessageConfig()
msc.isDisableNotification = true
message.messageConfig = msc
ios還能收到后臺推送通知;
于是就升級了,出現(xiàn)了連接初始化服務異常。
RongIMClient.connect(token, new RongIMClient.ConnectCallback() {
/**
* 連接融云成功
* @param userid 當前 token 對應的用戶 id
*/
@Override
public void onSuccess(String userid) {
// joinToRoom();
// 如果是token失效, 重新獲取token
Log.i(TAG, "MyApplication-->RongIMClient connect =======onSuccess");
}
/**
* 連接融云失敗
* @param connectionErrorCode 錯誤碼,可到官網(wǎng) 查看錯誤碼對應的注釋
*/
@Override
public void onError(RongIMClient.ConnectionErrorCode connectionErrorCode) {
Log.i(TAG, "MyApplication-->RongIMClient connect=======onError");
}
@Override
public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus databaseOpenStatus) {
Log.i(TAG, "MyApplication-->RongIMClient onDatabaseOpened");
}
});
就連這種最基本的連接回調都沒有,你沒聽錯,連error回調方法都不回調;超時也沒有,
這就很納悶了;
最后一路跟蹤idea的jar代碼,找到了問題所在;
在ConnectionService中,初始化服務里有一段代碼;
void initService(Context context, NativeObject obj, String akey) {
。。。
Resources resources = context.getResources();
this.mReconnectInterval = resources.getStringArray(resources.getIdentifier("rc_reconnect_interval", "array", context.getPackageName()));
int length = this.mReconnectInterval.length;
RLog.i("ConnectionService", "mReconnectInterval " + length);
if (length == 0 || this.mReconnectInterval[0] == null) {
throw new IllegalArgumentException("rc_reconnect_interval must have a value and the type of the field must be string-array");
}
if (length > 10) {
throw new IllegalArgumentException("The numbers of rc_reconnect_interval must less than 10");
}
。。。
}
這個getStringArray是獲取項目里的字符數(shù)組的,

配置文件rc_configuration.xml里是這樣的:
<integer-array name="rc_reconnect_interval">
<item>1</item>
<item>2</item>
<item>4</item>
<item>8</item>
<item>16</item>
<item>32</item>
<item>64</item>
<item>128</item>
<item>256</item>
<item>512</item>
</integer-array>
導致類型不匹配,獲取的個數(shù)和數(shù)據(jù)都是空的,
于是修改類型為string-array;如下;
<string-array name="rc_reconnect_interval">
<item>1</item>
<item>2</item>
<item>4</item>
<item>8</item>
<item>16</item>
<item>32</item>
<item>64</item>
<item>128</item>
<item>256</item>
<item>512</item>
</string-array>
然后服務初始化成功,可以正常連接和收發(fā)消息了,而且升級后,就真的關閉通知了,ios也不會收到后臺推送通知了,當前升級為5.1.2,
即:api "cn.rongcloud.sdk:im_lib:5.1.2"。
這里總結一下問題,升級替換sdk只關注了它的jar的庫文件,沒有關心攜帶的配置文件;
而且官方?jīng)]有提及這次升級改動配置的地方,這一點很坑;導致排查了很久;