接入友盟第三方登入與分享,判斷應用是否安裝

z小志發表於2018-01-23

接入友盟第三方登入與分享,我們需要判斷應用是否安裝或者是否支援,以微信為例:

/**
 *  平臺是否安裝
 *
 *  @param platformType 平臺型別 @see UMSocialPlatformType
 *
 *  @return YES 代表安裝,NO 代表未安裝
 *  @note 呼叫前請檢查是否配置好平臺相關白名單: http://dev.umeng.com/social/ios/quick-integration#1_3 
 *  在判斷QQ空間的App的時候,QQApi判斷會出問題
 */
 if UMSocialManager.default().isInstall(.wechatSession)  {
     //do you need
 }else{
     showError(msg: "請安裝最新版微信")
 }
複製程式碼

還有一種方法是

**
 *  當前平臺是否支援分享
 *
 *  @param platformType 平臺型別 @see UMSocialPlatformType
 *
 *  @return YES代表支援,NO代表不支援
 */
-(BOOL) isSupport:(UMSocialPlatformType)platformType;
複製程式碼

注:iOS9 之後有白名單,記得在info.plist 新增 LSApplicationQueriesSchemes 部分內容如下 :

<key>LSApplicationQueriesSchemes</key>
<array>
    <!-- 微信 URL Scheme 白名單-->
    <string>wechat</string>
    <string>weixin</string>

    <!-- 新浪微博 URL Scheme 白名單-->
    <string>sinaweibohd</string>
    <string>sinaweibo</string>
    <string>sinaweibosso</string>
    <string>weibosdk</string>
    <string>weibosdk2.5</string>

    <!-- QQ、Qzone、TIM URL Scheme 白名單-->
    <string>mqqapi</string>
    <string>mqq</string>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqqconnect</string>
    <string>mqqopensdkdataline</string>
    <string>mqqopensdkgrouptribeshare</string>
    <string>mqqopensdkfriend</string>
    <string>mqqopensdkapi</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqqopensdkapiV4</string>
    <string>mqzoneopensdk</string>
    <string>wtloginmqq</string>
    <string>wtloginmqq2</string>
    <string>mqqwpa</string>
    <string>mqzone</string>
    <string>mqzonev2</string>
    <string>mqzoneshare</string>
    <string>wtloginqzone</string>
    <string>mqzonewx</string>
    <string>mqzoneopensdkapiV2</string>
    <string>mqzoneopensdkapi19</string>
    <string>mqzoneopensdkapi</string>
    <string>mqqbrowser</string>
    <string>mttbrowser</string>
    <string>tim</string>
    <string>timapi</string>
    <string>timopensdkfriend</string>
    <string>timwpa</string>
    <string>timgamebindinggroup</string>
    <string>timapiwallet</string>
    <string>timOpensdkSSoLogin</string>
    <string>wtlogintim</string>
    <string>timopensdkgrouptribeshare</string>
    <string>timopensdkapiV4</string>
    <string>timgamebindinggroup</string>
    <string>timopensdkdataline</string>
    <string>wtlogintimV1</string>
    <string>timapiV1</string>

    <!-- 支付寶 URL Scheme 白名單-->
    <string>alipay</string>
    <string>alipayshare</string>

    <!-- 釘釘 URL Scheme 白名單-->
      <string>dingtalk</string>
      <string>dingtalk-open</string>

    <!--Linkedin URL Scheme 白名單-->
    <string>linkedin</string>
    <string>linkedin-sdk2</string>
    <string>linkedin-sdk</string>

    <!-- 點點蟲 URL Scheme 白名單-->
    <string>laiwangsso</string>

    <!-- 易信 URL Scheme 白名單-->
    <string>yixin</string>
    <string>yixinopenapi</string>

    <!-- instagram URL Scheme 白名單-->
    <string>instagram</string>

    <!-- whatsapp URL Scheme 白名單-->
    <string>whatsapp</string>

    <!-- line URL Scheme 白名單-->
    <string>line</string>

    <!-- Facebook URL Scheme 白名單-->
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>

    <!-- Kakao URL Scheme 白名單-->  
    <!-- 注:以下第一個引數需替換為自己的kakao appkey--> 
    <!-- 格式為 kakao + "kakao appkey"-->    
    <string>kakaofa63a0b2356e923f3edd6512d531f546</string>
    <string>kakaokompassauth</string>
    <string>storykompassauth</string>
    <string>kakaolink</string>
    <string>kakaotalk-4.5.0</string>
    <string>kakaostory-2.9.0</string>

   <!-- pinterest URL Scheme 白名單-->  
    <string>pinterestsdk.v1</string>

   <!-- Tumblr URL Scheme 白名單-->  
    <string>tumblr</string>

   <!-- 印象筆記 -->
    <string>evernote</string>
    <string>en</string>
    <string>enx</string>
    <string>evernotecid</string>
    <string>evernotemsg</string>

   <!-- 有道雲筆記-->
    <string>youdaonote</string>
    <string>ynotedictfav</string>
    <string>com.youdao.note.todayViewNote</string>
    <string>ynotesharesdk</string>

   <!-- Google+-->
    <string>gplus</string>

   <!-- Pocket-->
    <string>pocket</string>
    <string>readitlater</string>
    <string>pocket-oauth-v1</string>
    <string>fb131450656879143</string>
    <string>en-readitlater-5776</string>
    <string>com.ideashower.ReadItLaterPro3</string>
    <string>com.ideashower.ReadItLaterPro</string>
    <string>com.ideashower.ReadItLaterProAlpha</string>
    <string>com.ideashower.ReadItLaterProEnterprise</string>

   <!-- VKontakte-->
    <string>vk</string>
    <string>vk-share</string>
    <string>vkauthorize</string>
</array>


複製程式碼

相關文章