Commit 247b48b2 authored by 谢俊毅's avatar 谢俊毅
Browse files

init

No related merge requests found
Showing with 482 additions and 1 deletion
+482 -1
# coding: utf-8
Pod::Spec.new do |s|
s.name = "ErosPluginGeTui"
s.version = "1.0.1"
s.summary = "ErosPluginGeTui Source ."
s.homepage = 'https://github.com/bmfe/eros-plugin-ios-getui'
s.license = "MIT"
s.authors = { "xionghuayu" => "18601949015@163.com" }
s.platform = :ios
s.ios.deployment_target = "8.0"
s.source = { :git => 'https://github.com/bmfe/eros-plugin-ios-getui.git', :tag => s.version.to_s }
s.source_files = "Source/*.{h,m,mm}"
s.requires_arc = true
s.dependency 'GTSDK', '2.4.1.0-noidfa'
s.dependency 'WeexPluginLoader'
end
LICENSE 0 → 100644
MIT License
Copyright (c) 2018 本木医疗大前端
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
app ios所依赖的外部资源合集
\ No newline at end of file
# eros-plugin-ios-getui
\ No newline at end of file
//
// BMPushMessageManager.h
// BM-JYT
//
// Created by XHY on 2017/3/2.
// Copyright © 2017年 XHY. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <GTSDK/GeTuiSdk.h>
@interface BMPushMessageManager : NSObject <GeTuiSdkDelegate>
@property (nonatomic, assign) BOOL isLaunchedByNotification; // 是否点击推送信息进入app
+ (instancetype)shareInstance;
/** 获取cid */
+ (NSString *)getCid;
/** 配置推送服务 */
- (void)configPushService:(NSDictionary *)info;
/** 注册token */
+ (void)registerForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
/** 后台更新 */
+ (void)performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
/** ios10之前 收到push消息回调方法 */
+ (void)receiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
/**
用户点击推送消息打开app,会调用此方法注册一个监听首屏渲染完成的通知,然后再将推送内容 fire 给js
@pushMessage userInfo 消息体
*/
+ (void)addPushNotification:(NSDictionary *)pushMessage;
@end
//
// BMPushMessageManager.m
// BM-JYT
//
// Created by XHY on 2017/3/2.
// Copyright © 2017年 XHY. All rights reserved.
//
#import "BMPushMessageManager.h"
#import "BMGlobalEventManager.h"
#import "BMConfigManager.h"
#import "BMMediatorManager.h"
// iOS10 及以上需导入 UserNotifications.framework
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#import <UserNotifications/UserNotifications.h>
#endif
@interface BMPushMessageManager () <UNUserNotificationCenterDelegate>
{
NSString *_cid;
NSString *_deviceToken;
NSDictionary *_pushMessage;
}
@end
@implementation BMPushMessageManager
#pragma mark - Setter / Getter
#pragma mark - Private Method
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (instancetype)shareInstance
{
static BMPushMessageManager *_instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[BMPushMessageManager alloc] init];
});
return _instance;
}
- (instancetype)init
{
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
return self;
}
- (void)appDidEnterBackground
{
self.isLaunchedByNotification = YES;
}
- (void)appDidBecomeActive
{
self.isLaunchedByNotification = NO;
}
/**
解析push消息、透传消息
@param userInfo 消息体
*/
- (void)analysisRemoteNotification:(NSDictionary *)userInfo
{
if (![BMMediatorManager shareInstance].currentWXInstance) {
[[self class] addPushNotification:userInfo];
return;
}
[BMGlobalEventManager pushMessage:userInfo appLaunchedByNotification:self.isLaunchedByNotification];
}
/** 当首屏渲染完毕通知响应方法 */
- (void)firstScreenDidFinished:(NSNotification *)not
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.isLaunchedByNotification = YES;
[self analysisRemoteNotification:_pushMessage];
_pushMessage = nil;
});
[[NSNotificationCenter defaultCenter] removeObserver:[BMPushMessageManager shareInstance] name:BMFirstScreenDidFinish object:nil];
}
/* 注册push推送服务 */
- (void)registerRemoteNotification
{
/*
警告:Xcode8 需要手动开启"TARGETS -> Capabilities -> Push Notifications"
*/
/*
警告:该方法需要开发者自定义,以下代码根据 APP 支持的 iOS 系统不同,代码可以对应修改。
以下为演示代码,注意根据实际需要修改,注意测试支持的 iOS 系统都能获取到 DeviceToken
*/
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
if (!error) {
WXLogInfo(@"request authorization succeeded!");
}
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#else // Xcode 7编译会调用
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#endif
} else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
}
#pragma mark - Api Request
#pragma mark - Custom Delegate & DataSource
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId
{
/* 将cid保存 */
_cid = clientId;
WXLogInfo(@"GE TUI CID:%@",clientId);
if (_deviceToken) {
[GeTuiSdk registerDeviceToken:_deviceToken];
}
}
- (void)GeTuiSdkDidOccurError:(NSError *)error
{
WXLogInfo(@"GETUI OCCUR ERROR: %@",error);
}
- (void)GeTuiSDkDidNotifySdkState:(SdkStatus)aStatus
{
NSString *status = @"正在启动";
if (aStatus == SdkStatusStarted) {
status = @"正常运行";
} else if (aStatus == SdkStatusStoped)
{
status = @"暂停运行";
}
WXLogInfo(@"个推SDK状态变化:%@",status);
}
/** SDK收到透传消息回调 */
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
//收到个推消息
NSString *payloadMsg = nil;
if (payloadData) {
payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];
}
if (offLine || !payloadMsg || payloadMsg.length == 0) {
return;
}
/* 解析消息内容 */
NSData *data = [payloadMsg dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSString *payloadStr = dic[@"payload"];
data = [payloadStr dataUsingEncoding:NSUTF8StringEncoding];
dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
[self analysisRemoteNotification:dic];
}
#pragma mark - System Delegate & DataSource
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// iOS 10: App在前台获取到通知
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
WXLogInfo(@"willPresentNotification:%@", notification.request.content.userInfo);
NSDictionary *userInfo = notification.request.content.userInfo;
[self analysisRemoteNotification:userInfo];
// [ GTSdk ]:将收到的APNs信息传给个推统计
[GeTuiSdk handleRemoteNotification:userInfo];
// 根据APP需要,判断是否要提示用户Badge、Sound、Alert
// completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
// iOS 10: 点击通知进入App时触发,在该方法内统计有效用户点击数
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
WXLogInfo(@"didReceiveNotification:%@", response.notification.request.content.userInfo);
NSDictionary *userInfo = response.notification.request.content.userInfo;
[self analysisRemoteNotification:userInfo];
// [ GTSdk ]:将收到的APNs信息传给个推统计
[GeTuiSdk handleRemoteNotification:userInfo];
completionHandler();
}
#endif
#pragma mark - Public Method
- (void)configPushService:(NSDictionary *)info
{
[GeTuiSdk startSdkWithAppId:info[@"appId"]?:@""
appKey:info[@"appKey"]?:@""
appSecret:info[@"appSecret"]?:@""
delegate:self];
// [GeTuiSdk runBackgroundEnable:YES];
[self registerRemoteNotification];
}
+ (void)registerForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token = [self hexadecimalString:deviceToken];
[BMPushMessageManager shareInstance]->_deviceToken = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
WXLogInfo(@"deviceToken:%@", [BMPushMessageManager shareInstance]->_deviceToken);
// [3]:向个推服务器注册deviceToken
[GeTuiSdk registerDeviceToken:[BMPushMessageManager shareInstance]->_deviceToken];
}
+ (NSString *)hexadecimalString:(NSData *)data
{
const unsigned char *dataBuffer = (const unsigned char *)[data bytes];
if (!dataBuffer) {
return [NSString string];
}
NSUInteger dataLength = [data length];
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (int i = 0; i < dataLength; ++i) {
[hexString appendFormat:@"%02x", (unsigned int)dataBuffer[i]];
}
return [NSString stringWithString:hexString];
}
+ (void)performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[GeTuiSdk resume];
completionHandler(UIBackgroundFetchResultNewData);
}
+ (void)receiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[[BMPushMessageManager shareInstance] analysisRemoteNotification:userInfo];
// 将收到的APNs信息传给个推统计
[GeTuiSdk handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
+ (NSString *)getCid
{
return [BMPushMessageManager shareInstance]->_cid;
}
+ (void)addPushNotification:(NSDictionary *)pushMessage
{
[BMPushMessageManager shareInstance]->_pushMessage = pushMessage;
[[NSNotificationCenter defaultCenter] addObserver:[BMPushMessageManager shareInstance] selector:@selector(firstScreenDidFinished:) name:BMFirstScreenDidFinish object:nil];
}
@end
//
// BMPushModule.h
// BMBaseLibrary
//
// Created by XHY on 2018/4/12.
//
#import <Foundation/Foundation.h>
#import <WeexSDK/WeexSDK.h>
@interface BMPushModule : NSObject <WXModuleProtocol>
@end
//
// BMPushModule.m
// BMBaseLibrary
//
// Created by XHY on 2018/4/12.
//
#import "BMPushModule.h"
#import "BMPushMessageManager.h"
#import <WeexPluginLoader/WeexPluginLoader.h>
#import "NSDictionary+Util.h"
WX_PlUGIN_EXPORT_MODULE(bmPush, BMPushModule)
@implementation BMPushModule
@synthesize weexInstance;
WX_EXPORT_METHOD(@selector(getCid:));
WX_EXPORT_METHOD(@selector(initPush:));
- (void)initPush:(NSDictionary *)info
{
[[BMPushMessageManager shareInstance] configPushService:info];
}
/** 获取 cid */
-(void)getCid:(WXModuleCallback)callback
{
NSString * cid = [BMPushMessageManager getCid];
NSInteger resCode = cid.length > 0 ? BMResCodeSuccess : BMResCodeError;
if (callback) {
NSMutableDictionary * dict = nil;
if (cid.length > 0) {
dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:cid,@"cid",nil];
}
NSDictionary *resDic = [NSDictionary configCallbackDataWithResCode:resCode msg:nil data:dict];
callback(resDic);
}
}
@end
//
// Target_BMPush.h
// ErosPluginGeTui
//
// Created by XHY on 2018/4/24.
//
#import <Foundation/Foundation.h>
@interface Target_BMPush : NSObject
- (void)Action_registerForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)Action_setIsLaunchedByNotification:(NSNumber *)val;
- (void)Action_addPushNotification:(NSDictionary *)notificationPayload;
- (void)Action_receiveRemoteNotification:(NSDictionary *)info;
- (void)Action_performFetchWithCompletionHandler:(NSDictionary *)info;
@end
//
// Target_BMPush.m
// ErosPluginGeTui
//
// Created by XHY on 2018/4/24.
//
#import "Target_BMPush.h"
#import "BMPushMessageManager.h"
@implementation Target_BMPush
- (void)Action_registerForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[BMPushMessageManager registerForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)Action_setIsLaunchedByNotification:(NSNumber *)val
{
[[BMPushMessageManager shareInstance] setIsLaunchedByNotification:[val boolValue]];
}
- (void)Action_addPushNotification:(NSDictionary *)notificationPayload
{
[BMPushMessageManager addPushNotification:notificationPayload];
}
- (void)Action_receiveRemoteNotification:(NSDictionary *)info
{
[BMPushMessageManager receiveRemoteNotification:info[@"userInfo"] fetchCompletionHandler:info[@"block"]];
}
- (void)Action_performFetchWithCompletionHandler:(NSDictionary *)info
{
[BMPushMessageManager performFetchWithCompletionHandler:info[@"block"]];
}
@end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment