publish 1.0.1

This commit is contained in:
gta02
2018-06-08 16:29:41 +08:00
commit b4c42d0dbc
68 changed files with 5045 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.pbxproj -text

46
.gitignore vendored Normal file
View File

@@ -0,0 +1,46 @@
# OSX
#
.DS_Store
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# BUCK
buck-out/
\.buckd/
*.keystore

107
README.md Normal file
View File

@@ -0,0 +1,107 @@
# react-native-weibo-login
## Getting started
`$ npm install react-native-weibo-login --save`
### Mostly automatic installation
`$ react-native link react-native-weibo-login`
### Manual installation
#### iOS
1. Add `node_modules/react-native-weibo-login/ios/WeiboSDK.bundle` in you project, or else it will be crash.
2. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`, Go to `node_modules``react-native-weibo-login` and add `RCTWeiBo.xcodeproj`.
3. In XCode, in the project navigator, select your project.
Add
- libRCTWeiBo.a
- QuartzCore.framework
- ImageIO.framework
- SystemConfiguration.framework
- Security.framework
- CoreTelephony.framework
- CoreText.framework
- UIKit.framework
- Foundation.framework
- CoreGraphics.framework
- Photos.framework
- libz.tbd
- libsqlite3.tbd
to your project's `Build Phases``Link Binary With Libraries`.
4. In the project navigator, in `Targets``info``URL types`. Add new URL type, `Identifier` value is `com.weibo`, `URL Schemes` value is `wb` + `you weibo appKey`, such as: `wb2317411734`.
5. Right click `Info.plist` open as source code, insert the following lines:
```xml
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sinaweibohd</string>
<string>weibosdk</string>
<string>sinaweibo</string>
<string>weibosdk2.5</string>
</array>
```
6. Copy the following in `AppDelegate.m`:
```
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
```
#### Android
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.gratong.WeiBoPackage;` to the imports at the top of the file.
- Add `new WeiBoPackage()` to the list returned by the `getPackages()` method.
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-weibo-login'
project(':react-native-weibo-login').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-weibo-login/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-weibo-login')
```
4. Insert the following lines inside the allprojects block in `android/build.gradle`:
```
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
```
such as:
```
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
```
}
## Usage
```javascript
import * as WeiBo from 'react-native-weibo-login';
// 设置登录参数
let config = {
appKey:"2317411734",
scope: 'all',
redirectURI: 'https://api.weibo.com/oauth2/default.html',
}
WeiBo.login(config)
.then(res=>{
console.log('login success:',res)
}).catch(err=>{
console.log('login fail:',err)
})
```

3
WeiboLoginDemo/.babelrc Normal file
View File

@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}

View File

@@ -0,0 +1,6 @@
[android]
target = Google Inc.:Google APIs:23
[maven_repositories]
central = https://repo1.maven.org/maven2

View File

@@ -0,0 +1,54 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js
; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/
; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*
; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js
; Ignore polyfills
.*/Libraries/polyfills/.*
; Ignore metro
.*/node_modules/metro/.*
[include]
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/
[options]
emoji=true
module.system=haste
munge_underscores=true
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js
suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
[version]
^0.67.0

1
WeiboLoginDemo/.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.pbxproj -text

56
WeiboLoginDemo/.gitignore vendored Normal file
View File

@@ -0,0 +1,56 @@
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# BUCK
buck-out/
\.buckd/
*.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
# Bundle artifact
*.jsbundle

View File

@@ -0,0 +1 @@
{}

118
WeiboLoginDemo/App.js Normal file
View File

@@ -0,0 +1,118 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
Image,
} from 'react-native';
import * as WeiBo from 'react-native-weibo-login';
type Props = {};
export default class App extends Component<Props> {
constructor(props){
super(props);
this.state={
data:''
}
}
wbLogin=()=>{
// 设置登录参数
let config = {
appKey:"2317411734",
scope: 'all',
redirectURI: 'https://api.weibo.com/oauth2/default.html',
}
WeiBo.login(config)
.then(res=>{
console.log('login success:',res)
this.setState({data:res})
}).catch(err=>{
console.log('login fail:',err)
this.setState({data:err.errMsg})
})
}
renderWeiboLogin(){
return(
<View style={{marginTop:100}}>
<View style={{flexDirection:'row',alignItems:'center'}}>
<View style={styles.loginLine}></View>
<Text style={{fontSize:13,color:"#A0A0A0"}}> 第三方登录 </Text>
<View style={styles.loginLine}></View>
</View>
<View style={styles.loginContainer}>
<TouchableOpacity
activeOpacity={0.8}
onPress={this.wbLogin}
style={styles.loginItem}>
<Image
style={styles.loginIcon}
source={require('./src/login_weibo.png')}
/>
<Text style={styles.loginText}>微博</Text>
</TouchableOpacity>
</View>
</View>
)
}
render() {
return (
<View style={styles.container}>
<View style={{marginTop:100}}>
<Text style={styles.text}>微博登录回调信息:</Text>
<Text style={styles.text}>
{this.state.data?JSON.stringify(this.state.data):'未授权'}
</Text>
</View>
{this.renderWeiboLogin()}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal:20
},
text:{
fontSize:15,
lineHeight:25,
},
loginContainer:{
marginTop:25,
flexDirection:'row',
justifyContent:'space-around'
},
loginItem:{
alignItems:'center',
},
loginLine:{
flex:1,
backgroundColor:"#ECECEC",
height:1
},
loginIcon:{
width:50,
height:50
},
loginText:{
fontSize:13,
color:'#444444',
marginTop:10
},
});

View File

@@ -0,0 +1,65 @@
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#
lib_deps = []
for jarfile in glob(['libs/*.jar']):
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)
for aarfile in glob(['libs/*.aar']):
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
android_library(
name = "all-libs",
exported_deps = lib_deps,
)
android_library(
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)
android_build_config(
name = "build_config",
package = "com.weibologindemo",
)
android_resource(
name = "res",
package = "com.weibologindemo",
res = "src/main/res",
)
android_binary(
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)

View File

@@ -0,0 +1,151 @@
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.weibologindemo"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-weibo-login')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

View File

@@ -0,0 +1,70 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Disabling obfuscation is useful if you collect stack traces from production crashes
# (unless you are using a system that supports de-obfuscate the stack traces).
-dontobfuscate
# React Native
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
@com.facebook.common.internal.DoNotStrip *;
}
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
-dontwarn com.facebook.react.**
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
-dontwarn android.text.StaticLayout
# okhttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
# okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

View File

@@ -0,0 +1,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.weibologindemo">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>

View File

@@ -0,0 +1,15 @@
package com.weibologindemo;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "WeiboLoginDemo";
}
}

View File

@@ -0,0 +1,47 @@
package com.weibologindemo;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.gratong.WeiBoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new WeiBoPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">WeiboLoginDemo</string>
</resources>

View File

@@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -0,0 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}

View File

@@ -0,0 +1,20 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useDeprecatedNdk=true

Binary file not shown.

View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

164
WeiboLoginDemo/android/gradlew vendored Executable file
View File

@@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
WeiboLoginDemo/android/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1,8 @@
keystore(
name = "debug",
properties = "debug.keystore.properties",
store = "debug.keystore",
visibility = [
"PUBLIC",
],
)

View File

@@ -0,0 +1,4 @@
key.store=debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android

View File

@@ -0,0 +1,5 @@
rootProject.name = 'WeiboLoginDemo'
include ':react-native-weibo-login'
project(':react-native-weibo-login').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-weibo-login/android')
include ':app'

4
WeiboLoginDemo/app.json Normal file
View File

@@ -0,0 +1,4 @@
{
"name": "WeiboLoginDemo",
"displayName": "WeiboLoginDemo"
}

4
WeiboLoginDemo/index.js Normal file
View File

@@ -0,0 +1,4 @@
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('WeiboLoginDemo', () => App);

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
BuildableName = "libReact.a"
BlueprintName = "React-tvOS"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOS.app"
BlueprintName = "WeiboLoginDemo-tvOS"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOSTests.xctest"
BlueprintName = "WeiboLoginDemo-tvOSTests"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOSTests.xctest"
BlueprintName = "WeiboLoginDemo-tvOSTests"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOS.app"
BlueprintName = "WeiboLoginDemo-tvOS"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOS.app"
BlueprintName = "WeiboLoginDemo-tvOS"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "WeiboLoginDemo-tvOS.app"
BlueprintName = "WeiboLoginDemo-tvOS"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "83CBBA2D1A601D0E00E9B192"
BuildableName = "libReact.a"
BlueprintName = "React"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "WeiboLoginDemo.app"
BlueprintName = "WeiboLoginDemo"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "WeiboLoginDemoTests.xctest"
BlueprintName = "WeiboLoginDemoTests"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "WeiboLoginDemoTests.xctest"
BlueprintName = "WeiboLoginDemoTests"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "WeiboLoginDemo.app"
BlueprintName = "WeiboLoginDemo"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "WeiboLoginDemo.app"
BlueprintName = "WeiboLoginDemo"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "WeiboLoginDemo.app"
BlueprintName = "WeiboLoginDemo"
ReferencedContainer = "container:WeiboLoginDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,14 @@
/**
* 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 <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@end

View File

@@ -0,0 +1,43 @@
/**
* 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 <React/RCTLinkingManager.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:@"WeiboLoginDemo"
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];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
@end

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="WeiboLoginDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="548" y="455"/>
</view>
</objects>
</document>

View File

@@ -0,0 +1,53 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sinaweibohd</string>
<string>weibosdk</string>
<string>sinaweibo</string>
<string>weibosdk2.5</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>WeiboLoginDemo</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.weibo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wb2317411734</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>

View File

@@ -0,0 +1,16 @@
/**
* 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 <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,68 @@
/**
* 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 <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
@interface WeiboLoginDemoTests : XCTestCase
@end
@implementation WeiboLoginDemoTests
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
{
if (test(view)) {
return YES;
}
for (UIView *subview in [view subviews]) {
if ([self findSubviewInView:subview matching:test]) {
return YES;
}
}
return NO;
}
- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
__block NSString *redboxError = nil;
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
}
return NO;
}];
}
RCTSetLogFunction(RCTDefaultLogFunction);
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}
@end

View File

@@ -0,0 +1,23 @@
{
"name": "WeiboLoginDemo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-weibo-login": "^1.0.1"
},
"devDependencies": {
"babel-jest": "23.0.1",
"babel-preset-react-native": "4.0.0",
"jest": "23.1.0",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

38
android/build.gradle Normal file
View File

@@ -0,0 +1,38 @@
buildscript {
repositories {
jcenter()
// maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.sina.weibo.sdk:core:4.2.7:openDefaultRelease@aar'
}

18
android/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,18 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/heng/Desktop/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class com.sina.weibo.sdk.** { *; }

View File

@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gratong">
</manifest>

View File

@@ -0,0 +1,114 @@
package com.gratong;
import com.facebook.react.bridge.ActivityEventListener;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.BaseActivityEventListener;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.WbSdk;
import com.sina.weibo.sdk.auth.WbAuthListener;
import com.sina.weibo.sdk.auth.WbConnectErrorMessage;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.auth.WbAuthListener;
public class WeiBoModule extends ReactContextBaseJavaModule{
private final ReactApplicationContext mContext;
private static final String RCTWBEventName = "weibo_login";
/** 注意SsoHandler 仅当 SDK 支持 SSO 时有效 */
private SsoHandler mSsoHandler;
public WeiBoModule(ReactApplicationContext reactContext) {
super(reactContext);
mContext = reactContext;
reactContext.addActivityEventListener(mActivityEventListener);
}
private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
if (mSsoHandler != null) {
mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
}
}
};
@ReactMethod
public void login(final ReadableMap config, final Callback callback){
if (mSsoHandler == null){
String appKey = config.getString("appKey");
String redirectURI = config.getString("redirectURI");
String scope = config.getString("scope");
AuthInfo mAuthInfo = new AuthInfo(mContext, appKey, redirectURI, scope);
WbSdk.install(mContext,mAuthInfo);
mSsoHandler = new SsoHandler(mContext.getCurrentActivity());
}
mSsoHandler.authorize(new SelfWbAuthListener());
callback.invoke("Weibo open success.");
}
private class SelfWbAuthListener implements WbAuthListener{
@Override
public void onSuccess(final Oauth2AccessToken token) {
Log.d("'WbAuthListener:","onSuccess");
WritableMap map = new WritableNativeMap();
if (token.isSessionValid()) {
map.putString("accessToken", token.getToken());
map.putDouble("expirationDate", token.getExpiresTime());
map.putString("userID", token.getUid());
map.putString("refreshToken", token.getRefreshToken());
map.putInt("errCode", 0);
} else {
map.putInt("errCode", -1);
map.putString("errMsg", "token invalid");
}
map.putString("type", "WBAuthorizeResponse");
mContext.getJSModule(RCTNativeAppEventEmitter.class).emit(RCTWBEventName,map);
}
@Override
public void cancel() {
Log.d("'WbAuthListener:","cancel");
WritableMap map = new WritableNativeMap();
map.putString("type", "WBAuthorizeResponse");
map.putString("errMsg", "Cancel");
map.putInt("errCode", -1);
mContext.getJSModule(RCTNativeAppEventEmitter.class).emit(RCTWBEventName,map);
}
@Override
public void onFailure(WbConnectErrorMessage errorMessage) {
Log.d("WbAuthListener","onFailure: "+errorMessage.getErrorMessage());
WritableMap map = new WritableNativeMap();
map.putString("type", "WBAuthorizeResponse");
map.putString("errMsg", errorMessage.getErrorMessage());
map.putInt("errCode", -1);
mContext.getJSModule(RCTNativeAppEventEmitter.class).emit(RCTWBEventName,map);
}
}
@Override
public String getName() {
return "WeiBo";
}
}

View File

@@ -0,0 +1,32 @@
package com.gratong;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class WeiBoPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new WeiBoModule(reactContext));
return modules;
}
// @Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

51
index.js Normal file
View File

@@ -0,0 +1,51 @@
import { NativeModules, NativeEventEmitter } from 'react-native';
const { WeiBo } = NativeModules
//创建原生监听器
const WeiBoNativeEventEmitter = new NativeEventEmitter(WeiBo)
/*
* Scope 是 OAuth2.0 授权机制中 authorize 接口的一个参数。通过 Scope平台将开放更多的微博
* 核心功能给开发者,同时也加强用户隐私保护,提升了用户体验,用户在新 OAuth2.0 授权页中有权利
* 选择赋予应用的功能。
* 目前 Scope 支持传入多个 Scope 权限,用逗号分隔。
*
* 有关哪些 OpenAPI 需要权限申请请查看http://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI
* 关于 Scope 概念及注意事项请查看http://open.weibo.com/wiki/Scope
* */
const defaultScope = "all"
// 默认 'https://api.weibo.com/oauth2/default.html'
// 必须和sina微博开放平台中应用高级设置中的redirectURI设置的一致不然会登录失败
const defaultRedirectURI = "https://api.weibo.com/oauth2/default.html"
function checkConfig(config) {
if(!config.redirectURI) {
config.redirectURI = defaultRedirectURI
}
if(!config.scope) {
config.scope = defaultScope
}
}
let weiBoAuthListener
const WeiBoLoginEventName = 'weibo_login'
export function login(config={}) {
return new Promise((resolve,reject)=>{
checkConfig(config)
//此回调只会返回SDK是否调用成功授权登录是否成功通过监听返回
WeiBo.login(config,(status)=>{
console.log(status)
});
weiBoAuthListener = WeiBoNativeEventEmitter.addListener(WeiBoLoginEventName,(data)=>{
weiBoAuthListener.remove()
if(data.errCode == 0){ //login success
resolve(data)
}else{ //login fail
reject(data)
}
})
})
}

10
ios/RCTWeiBo.h Normal file
View File

@@ -0,0 +1,10 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTBridge.h>
#import <React/RCTEventEmitter.h>
@interface RCTWeiBo : RCTEventEmitter <RCTBridgeModule>
@end

168
ios/RCTWeiBo.m Normal file
View File

@@ -0,0 +1,168 @@
#import "RCTWeiBo.h"
#import "WeiboSDK.h"
#define RCTWBEventName (@"weibo_login")
BOOL registerSDK = NO; //if SDK registered
@interface RCTWeiBo() <WeiboSDKDelegate>
@end
@implementation RCTWeiBo{
bool hasListeners;
WBAuthorizeRequest *request;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents {
return @[RCTWBEventName];
}
// Will be called when this module's first listener is added.
-(void)startObserving {
hasListeners = YES;
// Set up any upstream listeners or background tasks as necessary
}
// Will be called when this module's last listener is removed, or on dealloc.
-(void)stopObserving {
hasListeners = NO;
// Remove upstream listeners, stop unnecessary background tasks
}
- (instancetype)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:)
name:@"RCTOpenURLNotification" object:nil];
}
return self;
}
- (void)handleOpenURL:(NSNotification *)note
{
NSDictionary *userInfo = note.userInfo;
NSString *url = userInfo[@"url"];
[WeiboSDK handleOpenURL:[NSURL URLWithString:url] delegate:self];
}
RCT_EXPORT_METHOD(login:(NSDictionary *)config :(RCTResponseSenderBlock)callback)
{
NSString *redirectURI = config[@"redirectURI"];
NSString *scope = config[@"scope"];
NSString *appKey = config[@"appKey"];
//SDK
if(!registerSDK){
#ifdef DEBUG
[WeiboSDK enableDebugMode:YES];
#endif
if([WeiboSDK registerApp:appKey]){
registerSDK = YES;
}
}
if(request == nil){
request = [WBAuthorizeRequest request];
request.redirectURI = redirectURI;
request.scope = scope;
}
BOOL success = [WeiboSDK sendRequest:request];
callback(@[success?@"Weibo open success.":@"Weibo open fail."]);
}
- (void)didReceiveWeiboRequest:(WBBaseRequest *)request
{
}
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response
{
NSMutableDictionary *body = [NSMutableDictionary new];
body[@"errCode"] = @(response.statusCode);
//
if ([response isKindOfClass:WBSendMessageToWeiboResponse.class])
{
body[@"type"] = @"WBSendMessageToWeiboResponse";
if (response.statusCode == WeiboSDKResponseStatusCodeSuccess)
{
WBSendMessageToWeiboResponse *sendResponse = (WBSendMessageToWeiboResponse *)response;
WBAuthorizeResponse *authorizeResponse = sendResponse.authResponse;
if (sendResponse.authResponse != nil) {
body[@"userID"] = authorizeResponse.userID;
body[@"accessToken"] = authorizeResponse.accessToken;
body[@"expirationDate"] = @([authorizeResponse.expirationDate timeIntervalSince1970]);
body[@"refreshToken"] = authorizeResponse.refreshToken;
}
}
else
{
body[@"errMsg"] = [self _getErrMsg:response.statusCode];
}
}
//
else if ([response isKindOfClass:WBAuthorizeResponse.class])
{
body[@"type"] = @"WBAuthorizeResponse";
if (response.statusCode == WeiboSDKResponseStatusCodeSuccess)
{
WBAuthorizeResponse *authorizeResponse = (WBAuthorizeResponse *)response;
body[@"userID"] = authorizeResponse.userID;
body[@"accessToken"] = authorizeResponse.accessToken;
body[@"expirationDate"] = @([authorizeResponse.expirationDate timeIntervalSince1970]*1000);
body[@"refreshToken"] = authorizeResponse.refreshToken;
}
else
{
body[@"errMsg"] = [self _getErrMsg:response.statusCode];
}
}
if (hasListeners) {
[self sendEventWithName:RCTWBEventName body:body];
}
}
- (NSString *)_getErrMsg:(NSInteger)errCode
{
NSString *errMsg = @"微博认证失败";
switch (errCode) {
case WeiboSDKResponseStatusCodeUserCancel:
errMsg = @"用户取消发送";
break;
case WeiboSDKResponseStatusCodeSentFail:
errMsg = @"发送失败";
break;
case WeiboSDKResponseStatusCodeAuthDeny:
errMsg = @"授权失败";
break;
case WeiboSDKResponseStatusCodeUserCancelInstall:
errMsg = @"用户取消安装微博客户端";
break;
case WeiboSDKResponseStatusCodePayFail:
errMsg = @"支付失败";
break;
case WeiboSDKResponseStatusCodeShareInSDKFailed:
errMsg = @"分享失败";
break;
case WeiboSDKResponseStatusCodeUnsupport:
errMsg = @"不支持的请求";
break;
default:
errMsg = @"位置";
break;
}
return errMsg;
}
@end

View File

@@ -0,0 +1,294 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
A82E006320C90DFC00312A3A /* RCTWeiBo.m in Sources */ = {isa = PBXBuildFile; fileRef = A82E006220C90DFC00312A3A /* RCTWeiBo.m */; };
A82E00A720C9214D00312A3A /* libWeiboSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A82E00A320C9214100312A3A /* libWeiboSDK.a */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
915450F31C3D1520000CBFD2 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
915450F51C3D1520000CBFD2 /* libRCTWeiBo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTWeiBo.a; sourceTree = BUILT_PRODUCTS_DIR; };
A82E006020C90DFC00312A3A /* RCTWeiBo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWeiBo.h; sourceTree = "<group>"; };
A82E006220C90DFC00312A3A /* RCTWeiBo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWeiBo.m; sourceTree = "<group>"; };
A82E006520C90E0500312A3A /* libWeiboSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWeiboSDK.a; path = libWeiboSDK/libWeiboSDK.a; sourceTree = "<group>"; };
A82E00A220C9214100312A3A /* WBHttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBHttpRequest.h; sourceTree = "<group>"; };
A82E00A320C9214100312A3A /* libWeiboSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeiboSDK.a; sourceTree = "<group>"; };
A82E00A420C9214100312A3A /* WeiboSDK.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = WeiboSDK.bundle; sourceTree = "<group>"; };
A82E00A520C9214200312A3A /* WeiboSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeiboSDK.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
915450F21C3D1520000CBFD2 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A82E00A720C9214D00312A3A /* libWeiboSDK.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
915450EC1C3D1520000CBFD2 = {
isa = PBXGroup;
children = (
A82E00A120C9211A00312A3A /* libWeiboSDK */,
A82E006020C90DFC00312A3A /* RCTWeiBo.h */,
A82E006220C90DFC00312A3A /* RCTWeiBo.m */,
915450F61C3D1520000CBFD2 /* Products */,
A82E006420C90E0500312A3A /* Frameworks */,
);
sourceTree = "<group>";
};
915450F61C3D1520000CBFD2 /* Products */ = {
isa = PBXGroup;
children = (
915450F51C3D1520000CBFD2 /* libRCTWeiBo.a */,
);
name = Products;
sourceTree = "<group>";
};
A82E006420C90E0500312A3A /* Frameworks */ = {
isa = PBXGroup;
children = (
A82E006520C90E0500312A3A /* libWeiboSDK.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
A82E00A120C9211A00312A3A /* libWeiboSDK */ = {
isa = PBXGroup;
children = (
A82E00A320C9214100312A3A /* libWeiboSDK.a */,
A82E00A220C9214100312A3A /* WBHttpRequest.h */,
A82E00A420C9214100312A3A /* WeiboSDK.bundle */,
A82E00A520C9214200312A3A /* WeiboSDK.h */,
);
name = libWeiboSDK;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
915450F41C3D1520000CBFD2 /* RCTWeiBo */ = {
isa = PBXNativeTarget;
buildConfigurationList = 915450FE1C3D1520000CBFD2 /* Build configuration list for PBXNativeTarget "RCTWeiBo" */;
buildPhases = (
915450F11C3D1520000CBFD2 /* Sources */,
915450F21C3D1520000CBFD2 /* Frameworks */,
915450F31C3D1520000CBFD2 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RCTWeiBo;
productName = RCTWeiboAPI;
productReference = 915450F51C3D1520000CBFD2 /* libRCTWeiBo.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
915450ED1C3D1520000CBFD2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = erica;
TargetAttributes = {
915450F41C3D1520000CBFD2 = {
CreatedOnToolsVersion = 7.2;
};
};
};
buildConfigurationList = 915450F01C3D1520000CBFD2 /* Build configuration list for PBXProject "RCTWeiBo" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 915450EC1C3D1520000CBFD2;
productRefGroup = 915450F61C3D1520000CBFD2 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
915450F41C3D1520000CBFD2 /* RCTWeiBo */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
915450F11C3D1520000CBFD2 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A82E006320C90DFC00312A3A /* RCTWeiBo.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
915450FC1C3D1520000CBFD2 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
915450FD1C3D1520000CBFD2 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
915450FF1C3D1520000CBFD2 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../react-native/Libraries/**",
"$(BUILT_PRODUCTS_DIR)/include/**",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/libWeiboSDK",
"$(PROJECT_DIR)",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
915451001C3D1520000CBFD2 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../react-native/Libraries/**",
"$(BUILT_PRODUCTS_DIR)/include/**",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/libWeiboSDK",
"$(PROJECT_DIR)",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
915450F01C3D1520000CBFD2 /* Build configuration list for PBXProject "RCTWeiBo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
915450FC1C3D1520000CBFD2 /* Debug */,
915450FD1C3D1520000CBFD2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
915450FE1C3D1520000CBFD2 /* Build configuration list for PBXNativeTarget "RCTWeiBo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
915450FF1C3D1520000CBFD2 /* Debug */,
915451001C3D1520000CBFD2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 915450ED1C3D1520000CBFD2 /* Project object */;
}

184
ios/WBHttpRequest.h Executable file
View File

@@ -0,0 +1,184 @@
//
// WBHttpRequest.h
// WeiboSDK
//
// Created by DannionQiu on 14-9-18.
// Copyright (c) 2014年 SINA iOS Team. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#pragma mark - WBHttpRequest and WBHttpRequestDelegate
@class WBHttpRequest;
/**
接收并处理来自微博sdk对于网络请求接口的调用响应 以及logOutWithToken的请求
*/
@protocol WBHttpRequestDelegate <NSObject>
/**
收到一个来自微博Http请求的响应
@param response 具体的响应对象
*/
@optional
- (void)request:(WBHttpRequest *)request didReceiveResponse:(NSURLResponse *)response;
/**
收到一个来自微博Http请求失败的响应
@param error 错误信息
*/
@optional
- (void)request:(WBHttpRequest *)request didFailWithError:(NSError *)error;
/**
收到一个来自微博Http请求的网络返回
@param result 请求返回结果
*/
@optional
- (void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result;
/**
收到一个来自微博Http请求的网络返回
@param data 请求返回结果
*/
@optional
- (void)request:(WBHttpRequest *)request didFinishLoadingWithDataResult:(NSData *)data;
/**
收到快速SSO授权的重定向
@param URI
*/
@optional
- (void)request:(WBHttpRequest *)request didReciveRedirectResponseWithURI:(NSURL *)redirectUrl;
@end
/**
微博封装Http请求的消息结构
*/
@interface WBHttpRequest : NSObject
{
NSURLConnection *connection;
NSMutableData *responseData;
}
/**
用户自定义请求地址URL
*/
@property (nonatomic, strong) NSString *url;
/**
用户自定义请求方式
支持"GET" "POST"
*/
@property (nonatomic, strong) NSString *httpMethod;
/**
用户自定义请求参数字典
*/
@property (nonatomic, strong) NSDictionary *params;
/**
WBHttpRequestDelegate对象用于接收微博SDK对于发起的接口请求的请求的响应
*/
@property (nonatomic, weak) id<WBHttpRequestDelegate> delegate;
/**
用户自定义TAG
用于区分回调Request
*/
@property (nonatomic, strong) NSString* tag;
/**
统一HTTP请求接口
调用此接口后将发送一个HTTP网络请求
@param url 请求url地址
@param httpMethod 支持"GET" "POST"
@param params 向接口传递的参数结构
@param delegate WBHttpRequestDelegate对象用于接收微博SDK对于发起的接口请求的请求的响应
@param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回
*/
+ (WBHttpRequest *)requestWithURL:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
delegate:(id<WBHttpRequestDelegate>)delegate
withTag:(NSString *)tag;
/**
统一微博Open API HTTP请求接口
调用此接口后将发送一个HTTP网络请求用于访问微博open api
@param accessToken 应用获取到的accessToken用于身份验证
@param url 请求url地址
@param httpMethod 支持"GET" "POST"
@param params 向接口传递的参数结构
@param delegate WBHttpRequestDelegate对象用于接收微博SDK对于发起的接口请求的请求的响应
@param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回
*/
+ (WBHttpRequest *)requestWithAccessToken:(NSString *)accessToken
url:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
delegate:(id<WBHttpRequestDelegate>)delegate
withTag:(NSString *)tag;
/**
取消网络请求接口
调用此接口后,将取消当前网络请求,建议同时[WBHttpRequest setDelegate:nil];
注意该方法只对使用delegate的request方法有效。无法取消任何使用block的request的网络请求接口。
*/
- (void)disconnect;
#pragma mark - block extension
typedef void (^WBRequestHandler)(WBHttpRequest *httpRequest,
id result,
NSError *error);
/**
统一微博Open API HTTP请求接口
调用此接口后将发送一个HTTP网络请求用于访问微博open api
@param url 请求url地址
@param httpMethod 支持"GET" "POST"
@param params 向接口传递的参数结构
@param queue 发起请求的NSOperationQueue对象如queue为nil,则在主线程([NSOperationQueue mainQueue])发起请求。
@param handler 接口请求返回调用的block方法
*/
+ (WBHttpRequest *)requestWithURL:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
queue:(NSOperationQueue*)queue
withCompletionHandler:(WBRequestHandler)handler;
/**
统一HTTP请求接口
调用此接口后将发送一个HTTP网络请求
@param url 请求url地址
@param httpMethod 支持"GET" "POST"
@param params 向接口传递的参数结构
@param queue 发起请求的NSOperationQueue对象如queue为nil,则在主线程([NSOperationQueue mainQueue])发起请求。
@param handler 接口请求返回调用的block方法
*/
+ (WBHttpRequest *)requestWithAccessToken:(NSString *)accessToken
url:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
queue:(NSOperationQueue*)queue
withCompletionHandler:(WBRequestHandler)handler;
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

675
ios/WeiboSDK.h Executable file
View File

@@ -0,0 +1,675 @@
//
// WeiboSDKHeaders.h
// WeiboSDKDemo
//
// Created by Wade Cheng on 4/3/13.
// Copyright (c) 2013 SINA iOS Team. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "WBHttpRequest.h"
typedef NS_ENUM(NSInteger, WeiboSDKResponseStatusCode)
{
WeiboSDKResponseStatusCodeSuccess = 0,//成功
WeiboSDKResponseStatusCodeUserCancel = -1,//用户取消发送
WeiboSDKResponseStatusCodeSentFail = -2,//发送失败
WeiboSDKResponseStatusCodeAuthDeny = -3,//授权失败
WeiboSDKResponseStatusCodeUserCancelInstall = -4,//用户取消安装微博客户端
WeiboSDKResponseStatusCodePayFail = -5,//支付失败
WeiboSDKResponseStatusCodeShareInSDKFailed = -8,//分享失败 详情见response UserInfo
WeiboSDKResponseStatusCodeUnsupport = -99,//不支持的请求
WeiboSDKResponseStatusCodeUnknown = -100,
};
@protocol WeiboSDKDelegate;
@protocol WBHttpRequestDelegate;
@class WBBaseRequest;
@class WBBaseResponse;
@class WBMessageObject;
@class WBImageObject;
@class WBBaseMediaObject;
@class WBHttpRequest;
@class PHAsset;
@class WBNewVideoObject;
/**
微博SDK接口类
*/
@interface WeiboSDK : NSObject
/**
检查用户是否安装了微博客户端程序
@return 已安装返回YES未安装返回NO
*/
+ (BOOL)isWeiboAppInstalled;
/**
检查用户是否可以通过微博客户端进行分享
@return 可以使用返回YES不可以使用返回NO
*/
+ (BOOL)isCanShareInWeiboAPP;
/**
检查用户是否可以使用微博客户端进行SSO授权
@return 可以使用返回YES不可以使用返回NO
*/
+ (BOOL)isCanSSOInWeiboApp;
/**
打开微博客户端程序
@return 成功打开返回YES失败返回NO
*/
+ (BOOL)openWeiboApp;
/**
获取微博客户端程序的itunes安装地址
@return 微博客户端程序的itunes安装地址
*/
+ (NSString *)getWeiboAppInstallUrl;
/**
获取当前微博SDK的版本号
@return 当前微博SDK的版本号
*/
+ (NSString *)getSDKVersion;
extern NSString * const WeiboSDKGetAidSucessNotification;
extern NSString * const WeiboSDKGetAidFailNotification;
/**
获取当前微博SDK的aid
返回的aid值可能为 nil ,当值为 nil 时会尝试获取 aid 值。
当获取成功( aid 值变为有效值SDK会发出名为 WeiboSDKGetAidSucessNotification 的通知,通知中带有 aid 值。
当获取失败时SDK会发出名为 WeiboSDKGetAidFailNotification 的通知,通知中带有 NSError 对象。
@return aid 用于广告的与设备信息相关的标识符
*/
+ (NSString *)getWeiboAid;
/**
向微博客户端程序注册第三方应用
@param appKey 微博开放平台第三方应用appKey
@return 注册成功返回YES失败返回NO
*/
+ (BOOL)registerApp:(NSString *)appKey;
/**
处理微博客户端程序通过URL启动第三方应用时传递的数据
需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用
@param url 启动第三方应用的URL
@param delegate WeiboSDKDelegate对象用于接收微博触发的消息
@see WeiboSDKDelegate
*/
+ (BOOL)handleOpenURL:(NSURL *)url delegate:(id<WeiboSDKDelegate>)delegate;
/**
发送请求给微博客户端程序,并切换到微博
请求发送给微博客户端程序之后,微博客户端程序会进行相关的处理,处理完成之后一定会调用 [WeiboSDKDelegate didReceiveWeiboResponse:] 方法将处理结果返回给第三方应用
@param request 具体的发送请求
@see [WeiboSDKDelegate didReceiveWeiboResponse:]
@see WBBaseResponse
*/
+ (BOOL)sendRequest:(WBBaseRequest *)request;
/**
收到微博客户端程序的请求后,发送对应的应答给微博客户端端程序,并切换到微博
第三方应用收到微博的请求后,异步处理该请求,完成后必须调用该函数将应答返回给微博
@param response 具体的应答内容
@see WBBaseRequest
*/
+ (BOOL)sendResponse:(WBBaseResponse *)response;
/**
设置WeiboSDK的调试模式
当开启调试模式时WeiboSDK会在控制台输出详细的日志信息开发者可以据此调试自己的程序。默认为 NO
@param enabled 开启或关闭WeiboSDK的调试模式
*/
+ (void)enableDebugMode:(BOOL)enabled;
/**
取消授权,登出接口
调用此接口后token将失效
@param token 第三方应用之前申请的Token
@param delegate WBHttpRequestDelegate对象用于接收微博SDK对于发起的接口请求的请求的响应
@param tag 用户自定义TAG,将通过回调WBHttpRequest实例的tag属性返回
*/
+ (void)logOutWithToken:(NSString *)token delegate:(id<WBHttpRequestDelegate>)delegate withTag:(NSString*)tag;
/**
呼起微博客户端或打开微博H5页面SDK自动检测是否安装微博客户端当调用SDK相关方法时
有的话呼起微博客户端定位到对应界面;
没有的话打开 webView 加载相应的微博H5页面
@param uid 用户id
@param mid 微博id
@param aid 文章id
*/
//连接到指定用户的微博个人主页,连接后可进行加关注等互动
+ (void)linkToUser:(NSString *)uid;
//连接到指定的单条微博详情页,连接后可对这条微博进行转、评、赞等互动
+ (void)linkToSingleBlog:(NSString *)uid blogID:(NSString *)mid;
//连接到指定的微博头条文章页
+ (void)linkToArticle:(NSString *)aid;
//分享到微博
+ (void)shareToWeibo:(NSString *)content;
//评论指定的微博
+ (void)commentToWeibo:(NSString *)mid;
//连接到微博搜索内容流
+ (void)linkToSearch:(NSString *)keyword;
//连接到我的微博消息流
+ (void)linkToTimeLine;
//连接到我的微博个人主页
+ (void)linkToProfile;
@end
/**
接收并处理来至微博客户端程序的事件消息
*/
@protocol WeiboSDKDelegate <NSObject>
/**
收到一个来自微博客户端程序的请求
收到微博的请求后,第三方应用应该按照请求类型进行处理,处理完后必须通过 [WeiboSDK sendResponse:] 将结果回传给微博
@param request 具体的请求对象
*/
- (void)didReceiveWeiboRequest:(WBBaseRequest *)request;
/**
收到一个来自微博客户端程序的响应
收到微博的响应后,第三方应用可以通过响应类型、响应的数据和 WBBaseResponse.userInfo 中的数据完成自己的功能
@param response 具体的响应对象
*/
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response;
@end
#pragma mark - DataTransferObject and Base Request/Response
/**
微博客户端程序和第三方应用之间传输数据信息的基类
*/
@interface WBDataTransferObject : NSObject
/**
自定义信息字典,用于数据传输过程中存储相关的上下文环境数据
第三方应用给微博客户端程序发送 request 时,可以在 userInfo 中存储请求相关的信息。
@warning userInfo中的数据必须是实现了 `NSCoding` 协议的对象,必须保证能序列化和反序列化
@warning 序列化后的数据不能大于10M
*/
@property (nonatomic, strong) NSDictionary *userInfo;
/**
发送该数据对象的SDK版本号
如果数据对象是自己生成的则sdkVersion为当前SDK的版本号如果是接收到的数据对象则sdkVersion为数据发送方SDK版本号
*/
@property (strong, nonatomic, readonly) NSString *sdkVersion;
/**
当用户没有安装微博客户端程序时是否提示用户打开微博安装页面
如果设置为YES当用户未安装微博时会弹出Alert询问用户是否要打开微博App的安装页面。默认为YES
*/
@property (nonatomic, assign) BOOL shouldOpenWeiboAppInstallPageIfNotInstalled;
@end
/**
微博SDK所有请求类的基类
*/
@interface WBBaseRequest : WBDataTransferObject
/**
返回一个 WBBaseRequest 对象
@return 返回一个*自动释放的*WBBaseRequest对象
*/
+ (id)request;
@end
/**
微博SDK所有响应类的基类
*/
@interface WBBaseResponse : WBDataTransferObject
/**
对应的 request 中的自定义信息字典
如果当前 response 是由微博客户端响应给第三方应用的,则 requestUserInfo 中会包含原 request.userInfo 中的所有数据
@see WBBaseRequest.userInfo
*/
@property (strong, nonatomic, readonly) NSDictionary *requestUserInfo;
/**
响应状态码
第三方应用可以通过statusCode判断请求的处理结果
*/
@property (nonatomic, assign) WeiboSDKResponseStatusCode statusCode;
/**
返回一个 WBBaseResponse 对象
@return 返回一个*自动释放的*WBBaseResponse对象
*/
+ (id)response;
@end
#pragma mark - Authorize Request/Response
/**
第三方应用向微博客户端请求认证的消息结构
第三方应用向微博客户端申请认证时,需要调用 [WeiboSDK sendRequest:] 函数, 向微博客户端发送一个 WBAuthorizeRequest 的消息结构。
微博客户端处理完后会向第三方应用发送一个结构为 WBAuthorizeResponse 的处理结果。
*/
@interface WBAuthorizeRequest : WBBaseRequest
/**
微博开放平台第三方应用授权回调页地址,默认为`http://`
参考 http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E#.E5.AE.A2.E6.88.B7.E7.AB.AF.E9.BB.98.E8.AE.A4.E5.9B.9E.E8.B0.83.E9.A1.B5
@warning 必须保证和在微博开放平台应用管理界面配置的“授权回调页”地址一致,如未进行配置则默认为`http://`
@warning 不能为空长度小于1K
*/
@property (nonatomic, strong) NSString *redirectURI;
/**
微博开放平台第三方应用scope多个scrope用逗号分隔
参考 http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E#scope
@warning 长度小于1K
*/
@property (nonatomic, strong) NSString *scope;
/**
当用户没有安装微博客户端或微博客户端过低无法支持SSO的时候是否弹出SDK自带的Webview进行授权
如果设置为YES当用户没有安装微博客户端或微博客户端过低无法支持SSO的时候会自动弹出SDK自带的Webview进行授权。
如果设置为NO会根据 shouldOpenWeiboAppInstallPageIfNotInstalled 属性判断是否弹出安装/更新微博的对话框
默认为YES
*/
@property (nonatomic, assign) BOOL shouldShowWebViewForAuthIfCannotSSO;
@end
/**
微博客户端处理完第三方应用的认证申请后向第三方应用回送的处理结果
WBAuthorizeResponse 结构中仅包含常用的 userID 、accessToken 和 expirationDate 信息,其他的认证信息(比如部分应用可以获取的 refresh_token 信息)会统一存放到 userInfo 中
*/
@interface WBAuthorizeResponse : WBBaseResponse
/**
用户ID
*/
@property (nonatomic, strong) NSString *userID;
/**
认证口令
*/
@property (nonatomic, strong) NSString *accessToken;
/**
认证过期时间
*/
@property (nonatomic, strong) NSDate *expirationDate;
/**
当认证口令过期时用于换取认证口令的更新口令
*/
@property (nonatomic, strong) NSString *refreshToken;
@end
#pragma mark - ProvideMessageForWeibo Request/Response
/**
微博客户端向第三方程序请求提供内容的消息结构
*/
@interface WBProvideMessageForWeiboRequest : WBBaseRequest
@end
/**
微博客户端向第三方应用请求提供内容,第三方应用向微博客户端返回的消息结构
*/
@interface WBProvideMessageForWeiboResponse : WBBaseResponse
/**
提供给微博客户端的消息
*/
@property (nonatomic, strong) WBMessageObject *message;
/**
返回一个 WBProvideMessageForWeiboResponse 对象
@param message 需要回送给微博客户端程序的消息对象
@return 返回一个*自动释放的*WBProvideMessageForWeiboResponse对象
*/
+ (id)responseWithMessage:(WBMessageObject *)message;
@end
#pragma mark - SendMessageToWeibo Request/Response
/**
第三方应用发送消息至微博客户端程序的消息结构体
*/
@interface WBSendMessageToWeiboRequest : WBBaseRequest
/**
发送给微博客户端的消息
*/
@property (nonatomic, strong) WBMessageObject *message;
/**
返回一个 WBSendMessageToWeiboRequest 对象
此方法生成对象被[WeiboSDK sendRequest:]会唤起微博客户端的发布器进行分享,如果未安装微博客户端或客户端版本太低
会根据 shouldOpenWeiboAppInstallPageIfNotInstalled 属性判断是否弹出安装/更新微博的对话框
@param message 需要发送给微博客户端的消息对象
@return 返回一个*自动释放的*WBSendMessageToWeiboRequest对象
*/
+ (id)requestWithMessage:(WBMessageObject *)message;
/**
返回一个 WBSendMessageToWeiboRequest 对象
当用户安装了可以支持微博客户端內分享的微博客户端时,会自动唤起微博并分享
当用户没有安装微博客户端或微博客户端过低无法支持通过客户端內分享的时候会自动唤起SDK內微博发布器
@param message 需要发送给微博的消息对象
@param authRequest 授权相关信息,与access_token二者至少有一个不为空,当access_token为空并且需要弹出SDK內发布器时会通过此信息先进行授权后再分享
@param access_token 第三方应用之前申请的Token,当此值不为空并且无法通过客户端分享的时候,会使用此token进行分享。
@return 返回一个*自动释放的*WBSendMessageToWeiboRequest对象
*/
+ (id)requestWithMessage:(WBMessageObject *)message
authInfo:(WBAuthorizeRequest *)authRequest
access_token:(NSString *)access_token;
@end
/**
WBSendMessageToWeiboResponse
*/
@interface WBSendMessageToWeiboResponse : WBBaseResponse
/**
可能在分享过程中用户进行了授权操作,当此值不为空时,为用户相应授权信息
*/
@property (nonatomic,strong) WBAuthorizeResponse *authResponse;
@end
#pragma mark - MessageObject / ImageObject
/**
微博客户端程序和第三方应用之间传递的消息结构
一个消息结构由三部分组成:文字、图片和多媒体数据。三部分内容中至少有一项不为空,图片和多媒体数据不能共存。(新版的多图和视频属于图片数据,并且图片和视频也不能共存)
*/
@interface WBMessageObject : NSObject
/**
消息的文本内容
@warning 长度小于2000个汉字
*/
@property (nonatomic, strong) NSString *text;
/**
消息的图片内容
@see WBImageObject
*/
@property (nonatomic, strong) WBImageObject *imageObject;
/**
消息的多媒体内容
@see WBBaseMediaObject
*/
@property (nonatomic, strong) WBBaseMediaObject *mediaObject;
/**
消息的视频内容
@see WBVideoObject
*/
@property (nonatomic, strong) WBNewVideoObject *videoObject;
/**
返回一个 WBMessageObject 对象
@return 返回一个*自动释放的*WBMessageObject对象
*/
+ (id)message;
@end
/**
图片视频分享时错误枚举
*/
typedef NS_ENUM(NSInteger, WBSDKMediaTransferErrorCode)
{
WBSDKMediaTransferAlbumPermissionError = 0,//相册权限
WBSDKMediaTransferAlbumWriteError = 0,//相册写入错误
WBSDKMediaTransferAlbumAssetTypeError = 0,//资源类型错误
};
/**
图片视频分享协议
*/
@protocol WBMediaTransferProtocol <NSObject>
/**
数据准备成功回调
*/
-(void)wbsdk_TransferDidReceiveObject:(id)object;
/**
数据准备失败回调
*/
-(void)wbsdk_TransferDidFailWithErrorCode:(WBSDKMediaTransferErrorCode)errorCode andError:(NSError*)error;
@end
/**
消息中包含的图片数据对象
*/
@interface WBImageObject : NSObject
/**
图片真实数据内容
@warning 大小不能超过10M
*/
@property (nonatomic, strong) NSData *imageData;
/**
是否分享到story
*/
@property (nonatomic) BOOL isShareToStory;
/**
返回一个 WBImageObject 对象
@return 返回一个*自动释放的*WBImageObject对象
*/
+ (id)object;
/**
返回一个 UIImage 对象
@return 返回一个*自动释放的*UIImage对象
*/
- (UIImage *)image;
/**
多图分享委托
*/
@property(nonatomic,weak)id<WBMediaTransferProtocol> delegate;
/**
图片对象添加图片数组
*/
- (void)addImages:(NSArray<UIImage *>*)imageArray;
/**
图片对象添加照片数组
*/
- (void)addImageAssets:(NSArray<PHAsset*>*)assetArray;
/**
多图最终传递对象
*/
-(NSArray*)finalAssetArray;
@end
@interface WBNewVideoObject : NSObject
/**
返回一个 WBNewVideoObject 对象
@return 返回一个*自动释放的*WBNewVideoObject对象
*/
+ (id)object;
/**
是否分享到story
*/
@property (nonatomic) BOOL isShareToStory;
/**
多图分享委托
*/
@property(nonatomic,weak)id<WBMediaTransferProtocol> delegate;
/**
视频对象添加视频
*/
-(void)addVideo:(NSURL*)videoUrl;
/**
视频对象添加视频资源
*/
-(void)addVideoAsset:(PHAsset*)videoAsset;
/**
视频最终传递对象
*/
-(NSString*)finalAsset;
@end
#pragma mark - Message Media Objects
/**
消息中包含的多媒体数据对象基类,该类后期会被废弃,在发布器不再显示为linkcard样式,只显示为普通网络连接
*/
@interface WBBaseMediaObject : NSObject
/**
对象唯一ID用于唯一标识一个多媒体内容
当第三方应用分享多媒体内容到微博时,应该将此参数设置为被分享的内容在自己的系统中的唯一标识
@warning 不能为空长度小于255
*/
@property (nonatomic, strong) NSString *objectID;
/**
多媒体内容标题
@warning 不能为空且长度小于1k
*/
@property (nonatomic, strong) NSString *title;
/**
多媒体内容描述
@warning 长度小于1k
*/
@property (nonatomic, strong) NSString *description;
/**
多媒体内容缩略图
@warning 大小小于32k
*/
@property (nonatomic, strong) NSData *thumbnailData;
/**
点击多媒体内容之后呼起第三方应用特定页面的scheme
@warning 长度小于255
*/
@property (nonatomic, strong) NSString *scheme;
/**
返回一个 WBBaseMediaObject 对象
@return 返回一个*自动释放的*WBBaseMediaObject对象
*/
+ (id)object;
@end
#pragma mark - Message WebPage Objects
/**
消息中包含的网页数据对象
*/
@interface WBWebpageObject : WBBaseMediaObject
/**
网页的url地址
@warning 不能为空且长度不能超过255
*/
@property (nonatomic, strong) NSString *webpageUrl;
@end

BIN
ios/libWeiboSDK.a Executable file

Binary file not shown.

29
package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "react-native-weibo-login",
"version": "1.0.1",
"description": "新浪微博登录模块",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/zhanguangao/react-native-weibo-login.git"
},
"keywords": [
"react-native",
"ios",
"android",
"weibo",
"sina",
"login"
],
"author": "zhanguangao",
"license": "ISC",
"bugs": {
"url": "https://github.com/zhanguangao/react-native-weibo-login/issues"
},
"homepage": "https://github.com/zhanguangao/react-native-weibo-login#readme"
}