美文网首页关于app安全性
iOS 应用内跳转商城

iOS 应用内跳转商城

作者: Gordon_gc | 来源:发表于2021-05-21 11:07 被阅读0次

    app有销售推广公司产品的需求(但不是主要功能,比如app是对公司的一款硬件所配套的软件,所以app主要的任务是更好的控制硬件,与硬件进行交互,但在app中我们还想推广其他产品),如果单独做这个功能费时费力(需要详情展示、支付、地址管理等等等),还有一种方案就是只做一个商品列表页面,点击直接跳转到对应的京东、淘宝等店铺或商品详情页面。

    跳到京东

    • 我们需要配置京东的白名单openapp.jdmobile
      在Info.plist中创建一个白名单列表LSApplicationQueriesSchemes,在列表中添加openapp.jdmobile
    • 我们需要获取到需要跳转到的店铺ID或商品ID(可以在电脑端打开对应的页面查看链接地址)
    • 对应的代码展示
      跳转店铺主页
    - (void)jshopMain:(NSString *)productID
    {
        NSString *urlStr = [NSString stringWithFormat:@"openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"jshopMain\",\"shopId\":\"%@\",\"sourceType\":\"homefloor\",\"sourceValue\":\"4384\",\"landPageId\":\"jshop.cx.mobile\"}", productID];
        NSURL *newUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil];
        if ([[UIApplication sharedApplication] canOpenURL:newUrl]) {
            [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil];
        }else{
            //直接跳转html
        }
    }
    

    跳转商品主页

    - (void)skuId:(NSString *)productID
    {
        NSString *urlStr = [NSString stringWithFormat:@"openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"productDetail\",\"skuId\":\"%@\",\"sourceType\":\"homefloor\",\"sourceValue\":\"4384\",\"landPageId\":\"jshop.cx.mobile\"}", productID];
        NSURL *newUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        if ([[UIApplication sharedApplication] canOpenURL:newUrl]) {
            [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil];
        }else{
            //直接跳转html
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS 应用内跳转商城

        本文链接:https://www.haomeiwen.com/subject/amvjjltx.html