封裝了一個騰訊雲im的flutter外掛

brzhang發表於2018-08-06

原文地址:地址

dim

封裝的一個騰訊雲im,以便於flutter開發者可以方便繼承im到自己的應用中

外掛地址:pub.dartlang.org/packages/di…

使用之前注意事項

開發者需要到騰訊雲上申請一個appid,申請地址

申請成功之後,平臺會分配一個appid給到開發者。

1、sig的獲取,sig一般就是開發者自己的後臺開發同學提供,可以參考騰訊雲文件實現sig申請。

2、都準備ok了,就可以登入imsdk了。

android 端配置你的專案中,android 目錄app下面的 AndroidManifest.xml,內容參考這裡

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.coinseast">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="coins_east"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!-- 【必須】訊息收發service -->
        <service
            android:name="com.tencent.qalsdk.service.QalService"
            android:exported="true"
            android:process=":QALSERVICE" >
        </service>
        <service
            android:name="com.tencent.qalsdk.service.QalAssistService"
            android:exported="false"
            android:process=":QALSERVICE" >
        </service>

        <!-- 【必須】 離線訊息廣播接收器 -->
        <receiver
            android:name="com.tencent.qalsdk.QALBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.tencent.qalsdk.broadcast.qal" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.tencent.qalsdk.core.NetConnInfoCenter" android:process=":QALSERVICE">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.TIME_SET" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
            </intent-filter>

            <!-- ImSDK 3.0.2 後新增 -->
            <intent-filter>
                <action android:name="com.tencent.qalsdk.service.TASK_REMOVED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>複製程式碼

ios端配置:

因為git上傳檔案必須要小於100m的限制,所以雲im有些framework上傳不了,因此需要開發者自己到這裡下載

下載好了zip包之後,把裡面的這些framework copy到 /Users/xxx/.pub-cache/hosted/pub.dartlang.org/dim-0.x.x/ios 目錄下(注意,執行fetch_libs.sh獲取所有的framework).

隨後到你的工程的ios資料夾中執行 pod install

然後就可以跑起來了。

如果不可以跑起來,報了這樣的錯誤。

 Undefined symbols for architecture x86_64:
             "operator new[](unsigned long, std::nothrow_t const&)", referenced from:
                 openbdh::BdhUpTransaction::initSegmentList() in ImSDK(bdhUpTransaction.o)
                 openbdh::BdhUpTransaction::getData(openbdh::DataTransInfo*) in ImSDK(bdhUpTransaction.o)
             "std::__1::__throw_system_error(int, char const*)", referenced from:
                 std::__1::unique_lock<std::__1::mutex>::unlock() in ImSDK(task_queue.o)
             "_uncompress", referenced from:複製程式碼

這說明你本地的一些庫沒有引用,用xcode開啟你的ios工程,然後參考這裡 這裡如何整合IMSDK寫的很清楚,需要依賴系統的那些庫。

注意:

1、引入的時候搜尋你會發現.dylib現在變為了.tbd了。還有就是IOS模擬器跑不了,騰訊雲沒有提供X86的framework。

2、注意不要引入IMUGCExt.framework,TXRTMPSDK.framework。

3、注意,當你升級dim之後,cache對應的版本中沒有這些庫了,因此要在copy一份過去,可以直接從你之前的版本中copy,在到ios工程下執行pod install

已有的功能

1、登入

2、登出

3、獲取會話列表

4、刪除一個會話

5、獲取會話訊息

6、傳送圖片訊息

7、傳送文字訊息



相關文章