分享房间和h5分享

This commit is contained in:
fengshuo
2021-11-24 14:31:24 +08:00
committed by zu
parent 463175f4f4
commit 02a0c55815
6 changed files with 152 additions and 28 deletions

View File

@@ -18,7 +18,18 @@
#import <MJExtension/MJExtension.h>
#import <RPSDK/RPSDK.h>
@interface WeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler, XCShareViewDelegate>
typedef NS_ENUM(NSUInteger, RightNavigationPushType){
///h5
RightNavigationPushType_Web = 1,
///
RightNavigationPushType_Share = 2,
///
RightNavigationPushType_AppPage = 3,
///
RightNavigationPushType_SharePicture = 5
};
@interface WeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
//WKScriptMessageHandler JavaScriptOC
@property (nonatomic, weak) id<WKScriptMessageHandler> scriptDelegate;
@@ -52,7 +63,8 @@
@property (strong, nonatomic) WKWebView *webview;
@property (strong, nonatomic) UIProgressView *progressView;
@property (nonatomic, strong) WKUserContentController *userContentController;
///
@property (nonatomic,copy) NSDictionary *shareDic;
@end
NSString * const kJSOpenPurse = @"openPurse";
@@ -63,6 +75,7 @@ NSString * const kJSGetDeviceId = @"getDeviceId";
NSString * const kJSGetTicket = @"getTicket";
NSString * const kJSGetDeviceInfo = @"getDeviceInfo";
NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
NSString * const kJSInitNav = @"initNav";
@implementation XPWebViewController
@@ -94,7 +107,17 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
NSString *currentUrl = [NSString stringWithFormat:@"%@", response];
if (currentUrl != nil && [currentUrl containsString:API_HOST_URL]) {
if ([message.name isEqualToString:kJSOpenSharePage]) {
[self showSharePanel];
if (message.body && message.body != [NSNull null]) {
NSDictionary *body;
//dic
if ([message.body isKindOfClass:[NSDictionary class]]) {
body = message.body;
} else if ([message.body isKindOfClass:[NSString class]]) {
body = [message.body toJSONObject];
}
self.shareDic = body[@"data"];
[self showSharePanel];
}
} else if ([message.name isEqualToString:kJSGetUid]) {
NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *js = [NSString stringWithFormat:@"getMessage(\"uid\",%@)", uid];
@@ -144,7 +167,9 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
}];
}];
#endif
}
} else if([message.name isEqualToString:kJSInitNav]) {
[self initNav:message.body];
}
}
}];
}
@@ -184,19 +209,50 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
[self.userContentController removeAllUserScripts];
}
}
#pragma mark -
- (void)initNav:(NSDictionary *)response{
if(!response || ![response isKindOfClass:[NSDictionary class]])return;
self.shareDic = response[@"data"];
if ([response[@"type"] intValue]== RightNavigationPushType_Web) {
[self addNavigationItemWithTitles:@[response[@"data"][@"title"]] titleColor:[ThemeColor alertTitleColor] isLeft:NO target:self action:@selector(gotoWebView) tags:nil];
}else if ([response[@"type"] intValue]== RightNavigationPushType_Share || [response[@"type"] intValue]== RightNavigationPushType_SharePicture){
[self addNavigationItemWithImageNames:@[@"family_person_share"] isLeft:NO
target:self action:@selector(showSharePanel) tags:nil];
}
}
- (void)gotoWebView {
if (self.shareDic[@"link"]) {
XPWebViewController * webVC = [[XPWebViewController alloc] init];
webVC.url = self.shareDic[@"link"];
[self.navigationController pushViewController:webVC animated:YES];
}
}
- (void)showSharePanel {
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
NSArray * items = @[wechat,cycle, qq, qqzone];
if (self.shareDic.allKeys.count <= 0) {
return;
}
NSDictionary * dic = self.shareDic;
XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init];
shareInfo.shareTitle = @"玩和平精英赢奖金";
shareInfo.shareContent = @"免费报名,奖金高,比赛多";
shareInfo.shareImageUrl = @"";
NSString * urlString = @"";
shareInfo.shareUrl = urlString;
shareInfo.shareTitle = self.shareDic[@"title"];
shareInfo.shareContent = dic[@"desc"];
shareInfo.shareImageUrl = dic[@"imgUrl"];
shareInfo.type = ShareType_H5;
NSString *urlStr = ((NSString *)dic[@"url"]).length > 0 ? dic[@"url"] : dic[@"showUrl"];
if (urlStr.length) {
if ([urlStr containsString:@"?"]) {
urlStr = [NSString stringWithFormat:@"%@&shareUid=%@",urlStr,[AccountInfoStorage instance].getUid];
} else {
urlStr = [NSString stringWithFormat:@"%@?shareUid=%@",urlStr,[AccountInfoStorage instance].getUid];
}
}
shareInfo.shareUrl = urlStr;
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagWeChat title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagQQ title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagQQZone title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
NSArray * items = @[wechat,cycle, qq, qqzone];
CGFloat margin = 15;
CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65);
XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo];
@@ -206,7 +262,34 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
#pragma mark - XCShareViewDelegate
- (void)shareViewDidClickCancle:(XPShareView *)shareView {
[TTPopup dismiss];
}
- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo {
[TTPopup dismiss];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSString *uid = [AccountInfoStorage instance].getUid;
NSString *ticket = [AccountInfoStorage instance].getTicket;
[params setObject:uid forKey:@"uid"];
[params setObject:@(shareInfo.shareType) forKey:@"shareType"];
[params setObject:ticket forKey:@"ticket"];
[params setObject:@(shareInfo.type) forKey:@"sharePageId"];
if (shareInfo.shareUrl.length > 0) {
[params setObject:shareInfo.shareUrl forKey:@"shareUrl"];
}
if (shareInfo.roomUid > 0) {
[params setObject:@(shareInfo.roomUid) forKey:@"targetUid"];
}
[HttpRequestHelper POST:@"usershare/save" params:params success:^(BaseModel * _Nonnull data) {
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
}];
}
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message {
[TTPopup dismiss];
[self showErrorToast:message];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
@@ -324,6 +407,8 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetDeviceInfo];
// :
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenFaceLiveness];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSInitNav];
}
return _userContentController;