React-native 社會化分享

一. 基于友盟封裝的React-native的社會化分享
傳送門: github
js調(diào)用方法:


SFUM

  • static share(text, img, url, title, platform, callback) //分享方法
  • static shareBoard(txt, img, url, title, platArr,callBack) //帶界面的分享方法(UM自帶但沒有分享鏈接)
  • static isInstall(plat,callback) //檢測平臺是否存在設(shè)備中

SFUmShareUI

  • <SFUmShareUI
    ref={(ref) => this.share = ref}
    onShare={(i, isLast) => this.clickItem(i, isLast)}
    platArray={['QQ', 'WechatSession', 'WechatTimeLine', 'WechatFavorite', 'Qzone', 'Facebook']}/> //帶分享鏈接的界面
// React native工程中 APP.JS中的分享示例
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {Component} from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    View
} from 'react-native';

const instructions = Platform.select({
    ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
    android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});
import {SFUmShareUI,SFUM} from 'react-native-sf-umshare'

type Props = {};
export default class App extends Component<Props> {
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome} onPress={() => {
                    this.share.setVisiable(true)
                }}>
                    Welcome to React Native!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit App.js
                </Text>
                <Text style={styles.instructions}>
                    {instructions}
                </Text>
                <SFUmShareUI
                    ref={(ref) => this.share = ref}
                    onShare={(i, isLast) => this.clickItem(i, isLast)}
                    platArray={['QQ', 'WechatSession', 'WechatTimeLine', 'WechatFavorite', 'Qzone', 'Facebook']}/>
            </View>
        );
    }

    clickItem = (i, isLast) => {
        if (isLast)
            alert('copy')
        else {
            var dic = {
                index: i,
                img: 'http://kplan.oss-cn-shanghai.aliyuncs.com/header/2017-11-27_1511778896586',
                text: 'text',
                url: 'http://kplan.oss-cn-shanghai.aliyuncs.com/header/2017-11-27_1511778896586',
                title: 'title',
            }
            this.share.setParams(dic, (data) => {
                this.share.setVisiable(false)
            })
        }
    }

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
});


//IOS 需要的配置    
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>


#import <UMShare/UMShare.h>
#import "RNUMConfigure.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"RNShare"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  
  [RNUMConfigure initWithAppkey:@"5ac479118f4a9d4acf0000f5" channel:@"App Store"];
  [self configUSharePlatforms];
  
  return YES;
}


- (void)configUSharePlatforms
{
  [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx852d43a16b2af151" appSecret:@"423f56cbcdd97217a44352805cb1f410" redirectURL:@"http://mobile.umeng.com/social"];
  [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1104484470"/*設(shè)置QQ平臺的appID*/  appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
  [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"1601664396"  appSecret:nil redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
}


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  //6.3的新的API調(diào)用,是為了兼容國外平臺(例如:新版facebookSDK,VK等)的調(diào)用[如果用6.2的api調(diào)用會沒有回調(diào)],對國內(nèi)平臺沒有影響
  BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
  if (!result) {
    // 其他如支付等SDK的回調(diào)
  }
  return result;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
  //6.3的新的API調(diào)用,是為了兼容國外平臺(例如:新版facebookSDK,VK等)的調(diào)用[如果用6.2的api調(diào)用會沒有回調(diào)],對國內(nèi)平臺沒有影響
  BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
  if (!result) {
    // 其他如支付等SDK的回調(diào)
  }
  return result;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
  BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
  if (!result) {
    // 其他如支付等SDK的回調(diào)
  }
  return result;
}


@end

其他平臺需要導(dǎo)入的庫和設(shè)置白名單 請見友盟
傳送門: github

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 組件暫支持: 微信,QQ,圍脖,復(fù)制粘貼 集成微信相關(guān)的分享 按照官方文檔,集成sdkcompile 'com.t...
    Cosecant閱讀 1,390評論 3 7
  • ¥開啟¥ 【iAPP實現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個線程,因...
    小菜c閱讀 7,330評論 0 17
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評論 19 139
  • 一向最討厭湊熱鬧,好評如潮的《老炮兒》自然對我沒有太大吸引力,周末難得閑來無事,正好姐們有vip賬號,本著不...
    任盈盈出品閱讀 518評論 0 0
  • 信花年華不長存,誓御怒馬踏破春。 醉臥空山聆風(fēng)樂,酩酊樹下悟禪尊。 也曾躊躇世間路,紅塵蹉跎誤紅塵。 大姊勸我取功...
    叁無閱讀 739評論 65 22

友情鏈接更多精彩內(nèi)容