@@ -18,6 +18,10 @@
# import "XCCurrentVCStackManager.h"
# import "XPMineUserInfoViewController.h"
# import "Api+Mine.h"
# import "YuMi-swift.h"
# import "RechargeStorage.h"
// / vc
# import "XPMineDressUpViewController.h"
# import "XPDressUpShopViewController.h"
@@ -89,6 +93,10 @@ typedef NS_ENUM(NSUInteger, RightNavigationPushType){
// /
@ property ( nonatomic , assign ) BOOL isCustom ;
@ property ( nonatomic , strong ) PIWebViewSavePhotoView * saveView ;
// / 订 单 编 号
@ property ( nonatomic , copy ) NSString * orderId ;
@ end
NSString * const kJSOpenPurse = @ "openPurse" ;
@@ -113,6 +121,8 @@ NSString * const kJSOpenChatPage = @"geToChatPage";
NSString * const kJSOpenAppConcernedChat = @ "openAppConcernedChat" ;
NSString * const kJSSavePictureShare = @ "savePictureShare" ;
NSString * const kJSGoToExchangeGold = @ "goToExchangeGold" ;
NSString * const kJSOpenPayment = @ "openPayment" ;
NSString * const kJSOpenPaymentCallback = @ "openPaymentCallback" ;
@ implementation XPWebViewController
@@ -229,9 +239,6 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold";
} ] ;
}
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
NSString * ticket = [ AccountInfoStorage instance ] . getTicket ;
[ Api getUserWalletInfo : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
@@ -279,7 +286,7 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold";
- ( void ) webView : ( WKWebView * ) webView decidePolicyForNavigationAction : ( WKNavigationAction * ) navigationAction decisionHandler : ( void ( ^ ) ( WKNavigationActionPolicy ) ) decisionHandler {
NSURL * URL = navigationAction . request . URL ;
NSString * scheme = [ URL scheme ] ;
NSURLRequest * request = navigationAction . request ;
NSURLRequest * request = navigationAction . request ;
// Judge is whether to jump to other app .
if ( ! [ scheme isEqualToString : @ "https" ] && ! [ scheme isEqualToString : @ "http" ] ) {
BOOL canOpen = [ [ UIApplication sharedApplication ] canOpenURL : request . URL ] ;
@@ -299,215 +306,394 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold";
NSURLCredential * card = [ [ NSURLCredential alloc ] initWithTrust : challenge . protectionSpace . serverTrust ] ;
completionHandler ( NSURLSessionAuthChallengeUseCredential , card ) ;
} ) ;
}
}
- ( void ) userContentController : ( WKUserContentController * ) userContentController didReceiveScriptMessage : ( WKScriptMessage * ) message {
[ self . webview evaluateJavaScript : @ "document.location.href" completionHandler : ^ ( id _Nullable response , NSError * _Nullable error ) {
NSLog ( @ "%@" , response ) ;
NSString * currentUrl = [ NSString stringWithFormat : @ "%@" , response ] ;
// / 测 试 环 境 只 要 有 host 就 执 行 , 方 便 h5 连 接 本 地 调 试
- ( void ) userContentController : ( WKUserContentController * ) userContentController
didReceiveScriptMessage : ( WKScriptMessage * ) message {
[ self . webview evaluateJavaScript : @ "document.location.href"
completionHandler : ^ ( id _Nullable response , NSError * _Nullable error ) {
NSLog ( @ "%@" , response ) ;
NSLog ( @ "-- -- - -- - -%@: %@" , message . name , message . body ) ;
NSString * currentUrl = [ NSString stringWithFormat : @ "%@" , response ] ;
// / 测 试 环 境 只 要 有 host 就 执 行 , 方 便 h5 连 接 本 地 调 试
BOOL condition = currentUrl ! = nil && [ currentUrl containsString : API_HOST _URL ] ;
# ifdef DEBUG
if ( currentUrl ! = nil ) {
# else
if ( currentUrl ! = nil && [ currentUrl containsString : API_HOST _URL ] ) {
condition = currentUrl ! = nil ;
# endif
if ( [ message . name isEqualToString : kJSOpenSharePage ] ) {
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 ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetTicket ] ) {
NSString * ticket = [ [ AccountInfoStorage instance ] getTicket ] ;
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" ticket \ ",\" % @ \ ")" , ticket ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetDeviceId ] ) {
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" deviceId \ ",\" % @ \ ")" , [ YYUtility deviceUniqueIdentification ] ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetDeviceInfo ] ) {
NSDictionary * basicParmars = [ HttpRequestHelper configBaseParmars : [ [ NSDictionary alloc ] init ] ] ;
NSString * json = [ basicParmars mj_JSONString ] ;
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" deviceInfo \ ",%@)" , json ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable ohter , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSOpenPurse ] ) {
} else if ( [ message . name isEqualToString : kJSChargePayPage ] ) {
// NSString * money = [ NSString stringWithFormat : @ "%@" , message . body ] ;
} else if ( [ message . name isEqualToString : kJSChargePayClickPage ] ) {
if ( message . body ! = nil && self . model . diamonds ! = nil ) {
// NSString * type = [ NSString stringWithFormat : @ "%@" , message . body ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenChargePage ] ) {
if ( self . delegate && [ self . delegate respondsToSelector : @ selector ( payHandler ) ] ) {
[ self . delegate payHandler ] ;
return ;
if ( condition ) {
if ( [ message . name isEqualToString : kJSOpenSharePage ] ) {
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 ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetTicket ] ) {
NSString * ticket = [ [ AccountInfoStorage instance ] getTicket ] ;
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" ticket \ ",\" % @ \ ")" , ticket ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetDeviceId ] ) {
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" deviceId \ ",\" % @ \ ")" , [ YYUtility deviceUniqueIdentification ] ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSGetDeviceInfo ] ) {
NSDictionary * basicParmars = [ HttpRequestHelper configBaseParmars : [ [ NSDictionary alloc ] init ] ] ;
NSString * json = [ basicParmars mj_JSONString ] ;
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" deviceInfo \ ",%@)" , json ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable ohter , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kJSOpenPurse ] ) {
} else if ( [ message . name isEqualToString : kJSChargePayPage ] ) {
// NSString * money = [ NSString stringWithFormat : @ "%@" , message . body ] ;
} else if ( [ message . name isEqualToString : kJSChargePayClickPage ] ) {
if ( message . body ! = nil && self . model . diamonds ! = nil ) {
// NSString * type = [ NSString stringWithFormat : @ "%@" , message . body ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenChargePage ] ) {
if ( self . delegate && [ self . delegate respondsToSelector : @ selector ( payHandler ) ] ) {
[ self . delegate payHandler ] ;
return ;
}
[ TTPopup dismiss ] ;
if ( self . isPush ) {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
return ;
}
UIViewController * controller = [ XCCurrentVCStackManager shareManager ] . getCurrentVC ;
if ( controller . presentingViewController ) {
[ controller dismissViewControllerAnimated : NO completion : nil ] ;
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 0.5 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
} ) ;
} else {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kOpenPersonPage ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . integerValue > 0 ) {
[ TTPopup dismiss ] ;
if ( self . isPush ) {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
return ;
}
UIViewController * controller = [ XCCurrentVCStackManager shareManager ] . getCurrentVC ;
if ( controller . presentingViewController ) {
[ controller dismissViewControllerAnimated : NO completion: nil ] ;
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 0.5 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
} ) ;
} else {
XPIAPRechargeViewController * webVC = [ [ XPIAPRechargeViewController alloc ] init ] ;
webVC . type = @ "4" ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : webVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kOpenPersonPage ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . integerValue > 0 ) {
[ TTPopup dismiss ] ;
XPMineUserInfoViewController * userInfoVC = [ [ XPMineUserInfoViewController alloc ] init ] ;
userInfoVC . uid = uid . integerValue ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : userInfoVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSInitNav ] ) {
[ self initNav : message . body ] ;
} else if ( [ message . name isEqualToString : kJSGetRoomUid ] ) {
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" roomUid \ ",\" % @ \ ")" , self . roomUid ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kInitShowNav ] ) {
if ( ( ( NSNumber * ) message . body ) . intValue = = 0 ) {
if ( self . InitShowNavBlock ) {
self . InitShowNavBlock ( YES ) ;
return ;
}
if ( self . navigationController ) {
[ self . navigationController setNavigationBarHidden : YES ] ;
}
}
} else if ( [ message . name isEqualToString : kCloseWebView ] ) {
if ( self . CloseWebViewBlock ) {
self . CloseWebViewBlock ( YES ) ;
XPMineUserInfoViewController * u serInfoVC = [ [ XPMineUserInfoViewController alloc ] init ] ;
userInfoVC . uid = uid . integerValue ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : userInfoVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSInitNav ] ) {
[ self initNav : message . body ] ;
} else if ( [ message . name isEqualToString : kJSGetRoomUid ] ) {
NSString * js = [ NSString stringWithFormat : @ "getMessage(\" roomUid \ ",\" % @ \ ")" , self . roomUid ] ;
[ self . webview evaluateJavaScript : js completionHandler : ^ ( id _Nullable other , NSError * _Nullable error ) {
NSLog ( @ "%@" , error ) ;
} ] ;
} else if ( [ message . name isEqualToString : kInitShowNav ] ) {
if ( ( ( NSNumber * ) message . body ) . intValue = = 0 ) {
if ( self . InitShowNavBlock ) {
self . InitShowNavBlock ( YES ) ;
return ;
}
if ( self . navigationController ) {
[ self . navigationController popViewControllerAnimated : YES ] ;
[ self . navigationController setNavigationBarHidden : YES ] ;
}
} else if ( [ message . name isEqualToString : kJumpAppointPage ] ) {
// h5 与 原 生 交 互 新 协 议
NSDictionary * bodyDict ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDict = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
NSString * str = ( NSString * ) message . body ;
bodyDict = [ str toJSONObject ] ;
}
NSInteger skyType = [ bodyDict [ @ "routerType" ] integerValue ] ;
[ self handleRouterType : skyType message : message ] ;
} else if ( [ message . name isEqualToString : kJSOpenChatPage ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
NIMSession * session = [ NIMSession session : uid type : NIMSessionTypeP2P ] ;
SessionViewController * sessionVC = [ [ SessionViewController alloc ] initWithSession : session ] ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : sessionVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenAppConcernedChat ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
NIMSession * session = [ NIMSession session : uid type : NIMSessionTypeP2P ] ;
SessionViewController * sessionVC = [ [ SessionViewController alloc ] initWithSession : session ] ;
sessionVC . isAttention = YES ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : sessionVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenRoom ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController . viewControllers enumerateObjectsUsingBlock : ^ ( __kindof UIViewController * _Nonnull obj , NSUInteger idx , BOOL * _Nonnull stop ) {
if ( [ obj isKindOfClass : [ XPRoomViewController class ] ] ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController popToRootViewControllerAnimated : NO ] ;
XPRoomViewController < RoomHostDelegate > * rooomVC = obj ;
[ rooomVC exitRoom ] ;
* stop = YES ;
}
} ] ;
if ( self . view . superview ) {
[ TTPopup dismiss ] ;
}
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 1 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
[ XPRoomViewController openRoom : uid viewController : [ XCCurrentVCStackManager shareManager ] . getCurrentVC ] ;
} ) ;
}
} else if ( [ message . name isEqualToString : kJSOpenRoomForGiftId ] ) {
NSLog ( @ "%@" , message . body ) ;
NSDictionary * bodyDict ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDict = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
NSString * str = ( NSString * ) message . body ;
bodyDict = [ str toJSONObject ] ;
}
// 房 间 页 传 参 : uid
NSString * uid = [ NSString stringWithFormat : @ "%@" , bodyDict [ @ "uid" ] ] ;
NSString * giftId = [ NSString stringWithFormat : @ "%@" , bodyDict [ @ "giftId" ] ] ;
if ( uid . length ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController . viewControllers enumerateObjectsUsingBlock : ^ ( __kindof UIViewController * _Nonnull obj , NSUInteger idx , BOOL * _Nonnull stop ) {
if ( [ obj isKindOfClass : [ XPRoomViewController class ] ] ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController popToRootViewControllerAnimated : NO ] ;
XPRoomViewController < RoomHostDelegate > * rooomVC = obj ;
[ rooomVC exitRoom ] ;
* stop = YES ;
}
} ] ;
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 1 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
[ XPRoomViewController openRoom : uid giftId : giftId viewController : [ XCCurrentVCStackManager shareManager ] . getCurrentVC ] ;
} ) ;
}
} else if ( [ message . name isEqualToString : kJSSavePictureShare ] ) {
NSDictionary * bodyDic ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDic = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
bodyDic = [ message . body toJSONObject ] ;
}
NSString * type = [ NSString stringWithFormat : @ "%@" , bodyDic [ @ "type" ] ] ;
if ( [ type isEqualToString : @ "2" ] ) {
[ self saveImageToPhotoAlbum : bodyDic ] ;
} else if ( [ type isEqualToString : @ "1" ] ) {
self . savePhotoDic = bodyDic ;
[ self showShareSavePhote ] ;
}
} else if ( [ message . name isEqualToString : kJSGoToExchangeGold ] ) {
XPIncomeRecordVC * incomeRecordVC = [ XPIncomeRecordVC new ] ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : incomeRecordVC animated : YES ] ;
}
}
} ] ;
}
} else if ( [ message . name isEqualToString : kCloseWebView ] ) {
if ( self . CloseWebViewBlock ) {
self . CloseWebViewBlock ( YES ) ;
return ;
}
if ( self . navigationController ) {
[ self . navigationController popViewControllerAnimated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJumpAppointPage ] ) {
// h5 与 原 生 交 互 新 协 议
NSDictionary * bodyDict ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDict = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
NSString * str = ( NSString * ) message . body ;
bodyDict = [ str toJSONObject ] ;
}
NSInteger skyType = [ bodyDict [ @ "routerType" ] integerValue ] ;
[ self handleRouterType : skyType message : message ] ;
} else if ( [ message . name isEqualToString : kJSOpenChatPage ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
NIMSession * session = [ NIMSession session : uid type : NIMSessionTypeP2P ] ;
SessionViewController * sessionVC = [ [ SessionViewController alloc ] initWithSession : session ] ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : sessionVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenAppConcernedChat ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
NIMSession * session = [ NIMSession session : uid type : NIMSessionTypeP2P ] ;
SessionViewController * sessionVC = [ [ SessionViewController alloc ] initWithSession : session ] ;
sessionVC . isAttention = YES ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : sessionVC animated : YES ] ;
}
} else if ( [ message . name isEqualToString : kJSOpenRoom ] ) {
NSString * uid = [ NSString stringWithFormat : @ "%@" , message . body ] ;
if ( uid . length > 0 ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController . viewControllers enumerateObjectsUsingBlock : ^ ( __kindof UIViewController * _Nonnull obj , NSUInteger idx , BOOL * _Nonnull stop ) {
if ( [ obj isKindOfClass : [ XPRoomViewController class ] ] ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController popToRootViewControllerAnimated : NO ] ;
XPRoomViewController < RoomHostDelegate > * rooomVC = obj ;
[ rooomVC exitRoom ] ;
* stop = YES ;
}
} ] ;
if ( self . view . superview ) {
[ TTPopup dismiss ] ;
}
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 1 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
[ XPRoomViewController openRoom : uid viewController : [ XCCurrentVCStackManager shareManager ] . getCurrentVC ] ;
} ) ;
}
} else if ( [ message . name isEqualToString : kJSOpenRoomForGiftId ] ) {
NSLog ( @ "%@" , message . body ) ;
NSDictionary * bodyDict ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDict = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
NSString * str = ( NSString * ) message . body ;
bodyDict = [ str toJSONObject ] ;
}
// 房 间 页 传 参 : uid
NSString * uid = [ NSString stringWithFormat : @ "%@" , bodyDict [ @ "uid" ] ] ;
NSString * giftId = [ NSString stringWithFormat : @ "%@" , bodyDict [ @ "giftId" ] ] ;
if ( uid . length ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController . viewControllers enumerateObjectsUsingBlock : ^ ( __kindof UIViewController * _Nonnull obj , NSUInteger idx , BOOL * _Nonnull stop ) {
if ( [ obj isKindOfClass : [ XPRoomViewController class ] ] ) {
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController popToRootViewControllerAnimated : NO ] ;
XPRoomViewController < RoomHostDelegate > * rooomVC = obj ;
[ rooomVC exitRoom ] ;
* stop = YES ;
}
} ] ;
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 1 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
[ XPRoomViewController openRoom : uid giftId : giftId viewController : [ XCCurrentVCStackManager shareManager ] . getCurrentVC ] ;
} ) ;
}
} else if ( [ message . name isEqualToString : kJSSavePictureShare ] ) {
NSDictionary * bodyDic ;
if ( [ message . body isKindOfClass : [ NSDictionary class ] ] ) {
bodyDic = message . body ;
} else if ( [ message . body isKindOfClass : [ NSString class ] ] ) {
bodyDic = [ message . body toJSONObject ] ;
}
NSString * type = [ NSString stringWithFormat : @ "%@" , bodyDic [ @ "type" ] ] ;
if ( [ type isEqualToString : @ "2" ] ) {
[ self saveImageToPhotoAlbum : bodyDic ] ;
} else if ( [ type isEqualToString : @ "1" ] ) {
self . savePhotoDic = bodyDic ;
[ self showShareSavePhote ] ;
}
} else if ( [ message . name isEqualToString : kJSGoToExchangeGold ] ) {
XPIncomeRecordVC * incomeRecordVC = [ XPIncomeRecordVC new ] ;
[ [ XCCurrentVCStackManager shareManager ] . getCurrentVC . navigationController pushViewController : incomeRecordVC animated : YES ] ;
} else if ( [ message . name isEqualToString : kJSOpenPayment ] ) {
[ self handleOpenPayment : message . body ] ;
}
}
} ] ;
}
# pragma mark - Payment Method
- ( void ) handleOpenPayment : ( NSString * ) chargeProdId {
# if DEBUG
chargeProdId = @ "com.hflighting.yumi.first.10" ;
# endif
if ( chargeProdId . length = = 0 ) {
[ self showErrorToast : @ "no charge ID" ] ;
return ;
}
[ self showLoading ] ;
@ kWeakify ( self ) ;
[ Api requestIAPRecharge : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
@ kStrongify ( self ) ;
[ self showErrorToast : @ "苹果下单 成功" ] ;
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) ( 2 * NSEC_PER _SEC ) ) , dispatch_get _main _queue ( ) , ^ {
switch ( code ) {
case 200 : {
NSString * orderId = ( NSString * ) data . data [ @ "recordId" ] ;
NSString * uuid = ( NSString * ) data . data [ @ "appAccountToken" ] ;
[ self handleGetIAPRechargeSuccess : orderId
uuid : uuid
chargeProdId : chargeProdId ] ;
}
break ;
case 50000 :
[ self showErrorToast : msg ] ;
break ;
default :
break ;
}
} ) ;
}
chargeProdId : chargeProdId
uid : [ AccountInfoStorage instance ] . getUid
ticket : [ AccountInfoStorage instance ] . getTicket
deviceInfo : [ YYUtility deviceID ]
clientIp : [ YYUtility ipAddress ] ] ;
}
- ( void ) handleGetIAPRechargeSuccess : ( NSString * ) orderID
uuid : ( NSString * ) uuid
chargeProdId : ( NSString * ) chargeProdId {
if ( orderID . length > 0 ) {
self . orderId = orderID ;
if ( @ available ( iOS 15.0 , * ) ) {
PIIAPRegulate * iap = [ PIIAPRegulate shared ] ;
[ iap demandCommodityThingWithProductId : chargeProdId
uuid : uuid
completionHandler : ^ ( NSError * _Nullable error ) {
} ] ;
@ kWeakify ( self ) ;
iap . ConditionBlock = ^ ( enum StoreConditionResult state , NSDictionary < NSString * , id > * _Nullable result ) {
@ kStrongify ( self ) ;
switch ( state ) {
case StoreConditionResultVerifiedServer : {
NSString * transactionId = result [ @ "transactionId" ] ;
NSLog ( @ "-- -- - -- - - transactionId: %@, orderID: %@" , transactionId , orderID ) ;
[ self rechargeSuccess : transactionId ] ;
}
break ;
case StoreConditionResultUnowned : {
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ XNDJTDDLoadingTool hideHUDInView : kWindow ] ;
[ self showErrorToast : YMLocalizedString ( @ "XPIAPRechargeViewController1" ) ] ;
} ) ;
}
break ;
case StoreConditionResultPay :
case StoreConditionResultStart :
break ;
default : {
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ XNDJTDDLoadingTool hideHUDInView : kWindow ] ;
[ self showErrorToast : YMLocalizedString ( @ "XPIAPRechargeViewController1" ) ] ;
} ) ;
}
break ;
}
} ;
} else {
[ XNDJTDDLoadingTool hideHUDInView : kWindow ] ;
[ self showErrorToast : YMLocalizedString ( @ "XPIAPRechargeViewController10" ) ] ;
}
} else {
[ XNDJTDDLoadingTool hideHUDInView : kWindow ] ;
}
}
// / 充 值 成 功 回 调 id
- ( void ) rechargeSuccess : ( NSString * ) transactionIdentifier {
// / 保 存 唯 一 凭 证
[ self saveRechageReciptWithTransactionIdentifier : transactionIdentifier ] ;
// / 二 次 验 证
@ kWeakify ( self ) ;
[ Api checkReceipt : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
@ kStrongify ( self ) ;
if ( code = = 200 ) {
} else {
}
}
chooseEnv : @ "true"
chargeRecordId : self . orderId
transcationId : transactionIdentifier
uid : [ AccountInfoStorage instance ] . getUid
ticket : [ AccountInfoStorage instance ] . getTicket ] ;
}
// / 充 值 成 功 之 后 保 存 订 单 到 钥 匙 串
- ( void ) saveRechageReciptWithTransactionIdentifier : ( NSString * ) transactionIdentifier {
NSData * receipt = [ NSData dataWithContentsOfURL : [ [ NSBundle mainBundle ] appStoreReceiptURL ] ] ;
NSString * encodeStr = [ receipt base64EncodedStringWithOptions : NSDataBase64EncodingEndLineWithLineFeed ] ;
NSMutableDictionary * dictionary = [ NSMutableDictionary dictionary ] ;
if ( transactionIdentifier ! = nil ) {
[ dictionary setObject : transactionIdentifier forKey : @ "transcationId" ] ;
}
if ( encodeStr ! = nil ) {
[ dictionary setObject : encodeStr forKey : @ "recipt" ] ;
}
if ( self . orderId ! = nil ) {
[ dictionary setObject : self . orderId forKey : @ "orderId" ] ;
}
if ( dictionary . allKeys . count = = 0 ) return ;
NSString * reciptJson = [ dictionary toJSONString ] ;
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
BOOL saveSuccess = [ RechargeStorage saveTranscationId : transactionIdentifier recipt : reciptJson uid : uid ] ;
if ( ! saveSuccess ) {
NSLog ( @ "保存订单失败" ) ;
}
}
// / 二 次 验 证 成 功
- ( void ) checkReceiptSuccess : ( NSString * ) transcationId {
[ XNDJTDDLoadingTool hideHUDInView : kWindow ] ;
if ( @ available ( iOS 15.0 , * ) ) {
PIIAPRegulate * iap = [ PIIAPRegulate shared ] ;
[ iap verifyBusinessAccomplishWithTransaction : [ NSString stringWithFormat : @ "%@" , transcationId ] completionHandler : ^ {
} ] ;
}
[ self deleteRechageReciptWithTransactionIdentifier : transcationId ] ;
[ self triggerOpenPaymentCallback : 200
orderID : self . orderId
productID : transcationId ] ;
}
// / 删 除 本 地 保 存 的
- ( void ) deleteRechageReciptWithTransactionIdentifier : ( NSString * ) transactionIdentifier {
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
BOOL deleteSuccess = [ RechargeStorage delegateTranscationId : transactionIdentifier
uid : uid ] ;
if ( deleteSuccess ) {
NSLog ( @ "删除本地账单失败" ) ;
}
}
- ( void ) triggerOpenPaymentCallback : ( NSInteger ) code
orderID : ( NSString * ) orderID
productID : ( NSString * ) productID {
NSDictionary * dic = @ { @ "code" : @ ( code ) , @ "orderId" : orderID , @ "productId" : productID } ;
NSString * js = [ NSString stringWithFormat : @ "openPaymentCallback(%@)" , dic . toJSONString ] ;
[ self . webview evaluateJavaScript : js
completionHandler : ^ ( id _Nullable result , NSError * _Nullable error ) {
} ] ;
}
# pragma mark - private method
- ( void ) handleRouterType : ( NSInteger ) skyType message : ( WKScriptMessage * ) message {
@@ -635,38 +821,37 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold";
}
- ( void ) showSharePanel {
if ( self . shareDic . allKeys . count <= 0 ) {
return ;
}
NSDictionary * dic = self . shareDic ;
XPShareInfoModel * shareInfo = [ [ XPShareInfoModel alloc ] init ] ;
shareInfo . shareTitle = self . shareDic [ @ "title" ] ;
shareInfo . shareContent = dic [ @ "desc" ] ;
shareInfo . shareImageUrl = dic [ @ "imgUrl" ] ;
shareInfo . type = ShareType_H5 ;
shareInfo . uid = [ AccountInfoStorage instance ] . getUid ;
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 : XPShareItemTagFaceBook title : @ "FaceBook" imageName : @ "share_fb" disableImageName : @ "share_fb" ] ;
XPShareItem * wechat = [ XPShareItem itemWitTag : XPShareItemTagLine title : @ "Line" imageName : @ "share_line" disableImageName : @ "share_line" ] ;
XPShareItem * qq = [ XPShareItem itemWitTag : XPShareItemTagCopyLink title : YMLocalizedString ( @ "XPWebViewNavView1" ) imageName : @ "share_copy_link" disableImageName : @ "share_copy_link" ] ;
XPShareItem * save = [ XPShareItem itemWitTag : XPShareItemTagAppSaveAlbum title : YMLocalizedString ( @ "PIWebViewSavePhotoView4" ) imageName : @ "share_save_icon" disableImageName : @ "share_save_icon" ] ;
NSArray * items = @ [ wechat , cycle , qq , save ] ;
CGFloat margin = 15 ;
CGSize itemSize = CGSizeMake ( ( KScreenWidth -2 * margin ) / 4 , 65 ) ;
XPShareView * shareView = [ [ XPShareView alloc ] initWithItems : items itemSize : itemSize shareInfo : shareInfo ] ;
shareView . delegate = self ;
if ( self . shareDic . allKeys . count <= 0 ) {
return ;
}
NSDictionary * dic = self . shareDic ;
XPShareInfoModel * shareInfo = [ [ XPShareInfoModel alloc ] init ] ;
shareInfo . shareTitle = self . shareDic [ @ "title" ] ;
shareInfo . shareContent = dic [ @ "desc" ] ;
shareInfo . shareImageUrl = dic [ @ "imgUrl" ] ;
shareInfo . type = ShareType_H5 ;
shareInfo . uid = [ AccountInfoStorage instance ] . getUid ;
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 : XPShareItemTagFaceBook title : @ "FaceBook" imageName : @ "share_fb" disableImageName : @ "share_fb" ] ;
XPShareItem * wechat = [ XPShareItem itemWitTag : XPShareItemTagLine title : @ "Line" imageName : @ "share_line" disableImageName : @ "share_line" ] ;
XPShareItem * qq = [ XPShareItem itemWitTag : XPShareItemTagCopyLink title : YMLocalizedString ( @ "XPWebViewNavView1" ) imageName : @ "share_copy_link" disableImageName : @ "share_copy_link" ] ;
XPShareItem * save = [ XPShareItem itemWitTag : XPShareItemTagAppSaveAlbum title : YMLocalizedString ( @ "PIWebViewSavePhotoView4" ) imageName : @ "share_save_icon" disableImageName : @ "share_save_icon" ] ;
[ TTPopup popupView : shareView style : TTPopupStyleActionSheet ] ;
NSArray * items = @ [ wechat , cycle , qq , save ] ;
CGFloat margin = 15 ;
CGSize itemSize = CGSizeMake ( ( KScreenWidth -2 * margin ) / 4 , 65 ) ;
XPShareView * shareView = [ [ XPShareView alloc ] initWithItems : items itemSize : itemSize shareInfo : shareInfo ] ;
shareView . delegate = self ;
[ TTPopup popupView : shareView style : TTPopupStyleActionSheet ] ;
}
# pragma mark - XCShareViewDelegate
@@ -856,8 +1041,10 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold";
[ _pi _userContentController addScriptMessageHandler : weakScriptMessageDelegate name : kJSSavePictureShare ] ;
// / 兑 换 金 币
[ _pi _userContentController addScriptMessageHandler : weakScriptMessageDelegate name : kJSGoToExchangeGold ] ;
// / 周 卡 内 购
[ _pi _userContentController addScriptMessageHandler : weakScriptMessageDelegate name : kJSOpenPayment ] ;
[ _pi _userContentController addScriptMessageHandler : weakScriptMessageDelegate name : kJSOpenPaymentCallback ] ;
}
return _pi _userContentController ;