|
@@ -11,7 +11,7 @@
|
|
|
#import "JYTabBarController.h"
|
|
|
#import <CoreLocation/CoreLocation.h>
|
|
|
|
|
|
-@interface JYNewSearchViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,CLLocationManagerDelegate>
|
|
|
+@interface JYNewSearchViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,CLLocationManagerDelegate,SKProductsRequestDelegate,SKPaymentTransactionObserver>
|
|
|
{
|
|
|
NSInteger _timeTick;
|
|
|
NSInteger _time;
|
|
@@ -95,6 +95,8 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
@"skipCamera",
|
|
|
@"skipAlbum",
|
|
|
@"openActivityPage",
|
|
|
+ @"callPhone",
|
|
|
+ @"inPurchasingVip",
|
|
|
];
|
|
|
for (NSString*jsName in jsArr) {
|
|
|
[config.userContentController addScriptMessageHandler:self name:jsName];
|
|
@@ -252,7 +254,7 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
|
|
|
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
|
|
|
// message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
|
|
|
-// NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
|
|
|
+ NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
|
|
|
if ([message.name isEqualToString:@"loginByWeixin"]) {
|
|
|
[self jsLoginByWeixin:message.body];
|
|
|
}else if ([message.name isEqualToString:@"share"]) {
|
|
@@ -293,6 +295,10 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
[self jsSkipAlbum:message.body];
|
|
|
}else if ([message.name isEqualToString:@"openActivityPage"]) {
|
|
|
[self jsOpenActivityPage:message.body];
|
|
|
+ }else if ([message.name isEqualToString:@"callPhone"]) {
|
|
|
+ [self jsCallPhone:message.body];
|
|
|
+ }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
|
|
|
+ [self jsInPurchasingVip:message.body];
|
|
|
}else {
|
|
|
|
|
|
}
|
|
@@ -304,7 +310,7 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
NSError *err = nil;
|
|
|
NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
|
|
|
-// NSLog(@"拦截prompt:%@",paramdict);
|
|
|
+ NSLog(@"拦截prompt:%@",paramdict);
|
|
|
if (!err){
|
|
|
NSString *type = [paramdict objectForKey:@"jsName"];
|
|
|
if (type && [type isEqualToString:@"getUserToken"]) {
|
|
@@ -445,7 +451,11 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
}];
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+- (void)viewDidUnload {
|
|
|
+ NSLog(@"viewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\nviewDidUnload\n");
|
|
|
+ [super viewDidUnload];
|
|
|
+ [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
|
|
|
+}
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
@@ -474,8 +484,12 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomOneListening) userInfo:nil repeats:YES];
|
|
|
|
|
|
|
|
|
+ //监听购买结果
|
|
|
+ [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
-(void)bottomOneListening {
|
|
|
if(self.tabBarController.selectedIndex == 0) {
|
|
|
[self judgeIsHiddenBottom];
|
|
@@ -1010,6 +1024,7 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+//统计点击推送
|
|
|
-(void)jsOpenActivityPage:(NSDictionary *)dict {
|
|
|
NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
|
|
|
@"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
|
|
@@ -1032,6 +1047,114 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
}
|
|
|
|
|
|
|
|
|
+//拨打电话
|
|
|
+-(void)jsCallPhone:(NSDictionary *)dict {
|
|
|
+ NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
|
|
|
+ NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//内购VIP
|
|
|
+-(void)jsInPurchasingVip:(NSDictionary *)dict {
|
|
|
+ NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
|
|
|
+ //产品id
|
|
|
+ if ([productid isEqualToString:@""]) {
|
|
|
+ NSLog(@"订单号 有问题");
|
|
|
+ [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常" delay:1];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果支付中"];
|
|
|
+ //监听购买结果
|
|
|
+ if([SKPaymentQueue canMakePayments]){
|
|
|
+ [self requestProductData:@"com.topnet.vip.000001"];
|
|
|
+ }else{
|
|
|
+ NSLog(@"不允许程序内付费");
|
|
|
+ [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"不允许程序内付费" delay:1];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//去苹果服务器请求商品
|
|
|
+- (void)requestProductData:(NSString *)type {
|
|
|
+ NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
|
|
|
+ NSSet *nsset = [NSSet setWithArray:product];
|
|
|
+ SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
|
|
|
+ request.delegate = self;
|
|
|
+ [request start];
|
|
|
+}
|
|
|
+- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
|
|
|
+ NSArray *myProduct = response.products;
|
|
|
+ if (myProduct.count == 0) {
|
|
|
+ NSLog(@"无法获取产品信息,购买失败。");
|
|
|
+ [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"无法获取产品信息,购买失败。" delay:1];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
|
|
|
+ [[SKPaymentQueue defaultQueue] addPayment:payment];
|
|
|
+}
|
|
|
+
|
|
|
+//监听购买结果
|
|
|
+- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
|
|
|
+ for (SKPaymentTransaction *transaction in transactions) {
|
|
|
+ switch (transaction.transactionState) {
|
|
|
+ case SKPaymentTransactionStatePurchased://交易完成
|
|
|
+ NSLog(@"购买成功transactionIdentifier = %@", transaction.transactionIdentifier);
|
|
|
+ [self completeTransaction:transaction];
|
|
|
+ break;
|
|
|
+ case SKPaymentTransactionStateFailed://交易失败
|
|
|
+ [self failedTransaction:transaction];
|
|
|
+ break;
|
|
|
+ case SKPaymentTransactionStateRestored://已经购买过该商品
|
|
|
+ [self restoreTransaction:transaction];
|
|
|
+ break;
|
|
|
+ case SKPaymentTransactionStatePurchasing://商品添加进列表
|
|
|
+ NSLog(@"商品添加进列表");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+ - (void)completeTransaction:(SKPaymentTransaction *)transaction {
|
|
|
+ // Your application should implement these two methods.
|
|
|
+
|
|
|
+ [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
+ NSString * productIdentifier = transaction.payment.productIdentifier;
|
|
|
+// NSString * receipt = [transaction.transactionReceipt base64EncodedString];
|
|
|
+ if ([productIdentifier length] > 0) {
|
|
|
+ // 向自己的服务器验证购买凭证
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ // Remove the transaction from the payment queue.
|
|
|
+ [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
|
|
|
+
|
|
|
+ }
|
|
|
+ - (void)failedTransaction:(SKPaymentTransaction *)transaction {
|
|
|
+ [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
+ if(transaction.error.code != SKErrorPaymentCancelled) {
|
|
|
+ NSLog(@"购买失败");
|
|
|
+ [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"购买失败,请重新尝试。" delay:1];
|
|
|
+ } else {
|
|
|
+ NSLog(@"用户取消交易");
|
|
|
+ [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"取消交易" delay:1];
|
|
|
+ }
|
|
|
+ [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
|
|
|
+ }
|
|
|
+ - (void)restoreTransaction:(SKPaymentTransaction *)transaction {\
|
|
|
+ // 对于已购商品,处理恢复购买的逻辑
|
|
|
+ NSLog(@"对于已购商品,处理恢复购买的逻辑");
|
|
|
+ [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
+ [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// web是否可退回上页面
|
|
|
-(int)jsIsCanBack:(NSString *)str{
|