Skip to content

Commit

Permalink
use new method to send event on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Jul 30, 2017
1 parent 53c229f commit b077d66
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# react-native-qq [![npm version](https://badge.fury.io/js/react-native-qq.svg)](http://badge.fury.io/js/react-native-qq)

React Native的QQ登录插件, react-native版本需要0.33.0及以上
React Native的QQ登录插件, react-native版本需要0.40.0及以上

## 如何安装

Expand Down
8 changes: 5 additions & 3 deletions index.js
@@ -1,9 +1,11 @@
/**
* Created by Yun on 2015-12-12.
*/
import {NativeModules, NativeAppEventEmitter} from 'react-native';
import { NativeModules, NativeEventEmitter } from 'react-native';

const {QQAPI} = NativeModules;
const { QQAPI } = NativeModules;

const QQAPIEmitter = new NativeEventEmitter(QQAPI);

function translateError(err, result) {
if (!err) {
Expand Down Expand Up @@ -47,7 +49,7 @@ function waitForResponse(type) {
});
}

NativeAppEventEmitter.addListener('QQ_Resp', resp => {
QQAPIEmitter.addListener('QQ_Resp', resp => {
const callback = savedCallback;
savedCallback = undefined;
callback && callback(resp);
Expand Down
7 changes: 2 additions & 5 deletions ios/RCTQQAPI/RCTQQAPI.h
Expand Up @@ -6,11 +6,8 @@
// Copyright © 2015 erica. All rights reserved.
//

#if __has_include(<React/RCTBridge.h>)
#import <React/RCTBridgeModule.h>
#else
#import "RCTBridgeModule.h"
#endif
#import <React/RCTEventEmitter.h>

#define RCTQQShareTypeNews @"news"
#define RCTQQShareTypeImage @"image"
Expand All @@ -24,6 +21,6 @@
#define RCTQQShareWebpageUrl @"webpageUrl"
#define RCTQQShareImageUrl @"imageUrl"

@interface RCTQQAPI : NSObject<RCTBridgeModule>
@interface RCTQQAPI : RCTEventEmitter<RCTBridgeModule>

@end
18 changes: 8 additions & 10 deletions ios/RCTQQAPI/RCTQQAPI.m
Expand Up @@ -12,17 +12,10 @@
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/QQApiInterfaceObject.h>

#if __has_include(<React/RCTBridge.h>)
#import <React/RCTLog.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTImageLoader.h>
#else
#import "RCTLog.h"
#import "RCTEventDispatcher.h"
#import "RCTBridge.h"
#import "RCTImageLoader.h"
#endif

//#define NOT_REGISTERED (@"registerApp required.")
#define INVOKE_FAILED (@"QQ API invoke returns false.")
Expand All @@ -45,6 +38,11 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

- (NSArray<NSString *> *)supportedEvents
{
return @[@"QQ_Resp"];
}

- (instancetype)init
{
self = [super init];
Expand Down Expand Up @@ -259,7 +257,7 @@ - (void)onResp:(QQBaseResp *)resp
body[@"result"] =resp.result;
body[@"extendInfo"] =resp.extendInfo;

[self.bridge.eventDispatcher sendAppEventWithName:@"QQ_Resp" body:body];
[self sendEventWithName:@"QQ_Resp" body:body];
}

- (void)isOnlineResponse:(NSDictionary *)response
Expand All @@ -277,7 +275,7 @@ - (void)tencentDidLogin
body[@"expires_in"] = @([_qqapi.expirationDate timeIntervalSince1970]*1000);
body[@"oauth_consumer_key"] =_qqapi.appId;

[self.bridge.eventDispatcher sendAppEventWithName:@"QQ_Resp" body:body];
[self sendEventWithName:@"QQ_Resp" body:body];
}

- (void)tencentDidNotLogin:(BOOL)cancelled
Expand All @@ -290,7 +288,7 @@ - (void)tencentDidNotLogin:(BOOL)cancelled
else {
body[@"errMsg"] = @"login failed";
}
[self.bridge.eventDispatcher sendAppEventWithName:@"QQ_Resp" body:body];
[self sendEventWithName:@"QQ_Resp" body:body];

}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-qq",
"version": "2.0.5",
"version": "3.0.0",
"description": "QQ Login&Share support in React Native.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b077d66

Please sign in to comment.