[object-c开发相关技术]
苹果内购 in-purchase无效产品id的问题是什么?商品ID对应应该详细如何对应?优雅草卓
苹果内购 in-purchase无效产品id的问题是什么?商品ID对应应该详细如何对应?优雅草卓伊凡引言 由于最近有个客户咨询关于 苹果内购 in-purchase 的问题做了付费咨询处理,得到第二个问题:“现在的项目可以运行。但运行后。iPhone 模拟器没有什么输出,如下图所示 首先是info.list这里有错 我们删掉 ViewController.m文件中的问题,它包含了一个不正确的注释行,可能会导致编译问题。 更新Main.storyboard,使其使用功能更完整的IAPStoreViewController作为主视图控制器,并添加必要的UI元素。
 <subviews> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6sJ-7j-wyX"> <rect key="frame" x="61.5" y="150" width="270" height="44"/> <color key="backgroundColor" red="0.0" green="0.4784313725" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> <connections> <action selector="purchaseProduct1:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Z5C-2o-4J1"/> </connections> </button> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3iO-0Z-f6d"> <rect key="frame" x="61.5" y="220" width="270" height="44"/> <color key="backgroundColor" red="0.0" green="0.4784313725" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> <connections> <action selector="purchaseProduct2:" destination="BYZ-38-t0r" eventType="touchUpInside" id="d5J-HX-y0v"/> </connections> </button> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9n3-3X-s3v"> <rect key="frame" x="61.5" y="290" width="270" height="44"/> <color key="backgroundColor" red="0.0" green="0.4784313725" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> <connections> <action selector="purchaseProduct3:" destination="BYZ-38-t0r" eventType="touchUpInside" id="XcF-5q-rj1"/> </connections> </button> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Jc3-2R-4gZ"> <rect key="frame" x="61.5" y="360" width="270" height="44"/> <color key="backgroundColor" red="0.5019607843" green="0.5019607843" blue="0.5019607843" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> <connections> <action selector="restorePurchases:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hWj-Qn-6fZ"/> </connections> </button> <activityIndicatorView hidden="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FdM-5J-y0E"> <rect key="frame" x="181.5" y="120" width="30" height="30"/> <color key="color" red="0.0" green="0.4784313725" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> </activityIndicatorView> <label userLabel="Title" text="应用内购买示例" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CnK-9v-1aX"> <rect key="frame" x="0.0" y="80" width="393" height="40"/> <fontDescription key="fontDescription" type="system" pointSize="24" weight="bold"/> <nil key="highlightedColor"/> </label> </subviews> <constraints> <constraint firstItem="6sJ-7j-wyX" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="61.5" id="1wM-gA-DUx"/> <constraint firstAttribute="trailing" secondItem="6sJ-7j-wyX" secondAttribute="trailing" constant="61.5" id="2qD-3Y-H7z"/> <constraint firstItem="3iO-0Z-f6d" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="61.5" id="3Y6-1v-3mQ"/> <constraint firstAttribute="trailing" secondItem="3iO-0Z-f6d" secondAttribute="trailing" constant="61.5" id="5aJ-Lh-Kh3"/> <constraint firstItem="Jc3-2R-4gZ" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="61.5" id="652-5N-RjJ"/> <constraint firstItem="9n3-3X-s3v" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="61.5" id="85n-41-2Bj"/> <constraint firstAttribute="trailing" secondItem="9n3-3X-s3v" secondAttribute="trailing" constant="61.5" id="93c-v9-2jT"/> <constraint firstAttribute="trailing" secondItem="Jc3-2R-4gZ" secondAttribute="trailing" constant="61.5" id="AgZ-2g-vBf"/> <constraint firstItem="FdM-5J-y0E" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="DzU-7o-4H7"/> <constraint firstItem="FdM-5J-y0E" firstAttribute="top" secondItem="CnK-9v-1aX" secondAttribute="bottom" constant="10" id="F7M-Hn-4Vh"/> <constraint firstItem="CnK-9v-1aX" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="40" id="H8N-7h-cr9"/> <constraint firstItem="6sJ-7j-wyX" firstAttribute="top" secondItem="FdM-5J-y0E" secondAttribute="bottom" constant="20" id="Hz5-mW-Jv2"/> <constraint firstItem="3iO-0Z-f6d" firstAttribute="top" secondItem="6sJ-7j-wyX" secondAttribute="bottom" constant="30" id="O5p-1Z-y8y"/> <constraint firstItem="9n3-3X-s3v" firstAttribute="top" secondItem="3iO-0Z-f6d" secondAttribute="bottom" constant="30" id="UaD-Dv-1y5"/> <constraint firstItem="Jc3-2R-4gZ" firstAttribute="top" secondItem="9n3-3X-s3v" secondAttribute="bottom" constant="30" id="X2K-7m-Ld3"/> <constraint firstItem="6sJ-7j-wyX" firstAttribute="height" constant="44" id="eYk-Mj-uH1"/> <constraint firstItem="3iO-0Z-f6d" firstAttribute="height" constant="44" id="fDd-P2-7U3"/> <constraint firstItem="9n3-3X-s3v" firstAttribute="height" constant="44" id="gG6-6v-3Qx"/> <constraint firstItem="Jc3-2R-4gZ" firstAttribute="height" constant="44" id="jD5-55-3vX"/> <constraint firstAttribute="trailing" secondItem="CnK-9v-1aX" secondAttribute="trailing" id="vDf-3j-8qL"/> <constraint firstItem="CnK-9v-1aX" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="x9Y-2k-kY8"/> </constraints> </view> <connections> <outlet property="loadingIndicator" destination="FdM-5J-y0E" id="t2b-v6-4rH"/> <outlet property="purchaseButton1" destination="6sJ-7j-wyX" id="oQf-Q9-xr8"/> <outlet property="purchaseButton2" destination="3iO-0Z-f6d" id="nWg-4T-rj9"/> <outlet property="purchaseButton3" destination="9n3-3X-s3v" id="qVw-7w-3pT"/> <outlet property="restoreButton" destination="Jc3-2R-4gZ" id="bV3-7j-7fW"/> </connections>然后开始第四步 然后关于无效产品标识的原因是 关于”无效产品ID:001Liu”的解释这个问题是预期的,原因是: - 1.
代码中使用了产品ID 001Liu 、 002Liu 和 003Liu - 2.
但是这些产品ID尚未在App Store Connect中配置 - 3.
当调用 requestProductsWithIdentifiers 方法时,App Store会验证这些ID,如果不存在则返回为无效ID
为了准确回答苹果内购产品ID的后台配置方法以及客户端对应的填写位置,我需要先通过网络搜索获取App Store Connect的最新配置步骤。 toolName: web_search status: success query: 苹果内购产品ID配置步骤 App Store Connect 之前的搜索结果未找到苹果内购产品ID的配置方法,我需要使用更精确的关键词重新搜索。 toolName: web_search status: success query: App Store Connect 内购产品ID配置步骤 苹果内购产品ID的配置流程及客户端对应关系如下: 一、App Store Connect后台配置步骤准备工作 - 确保已签署《付费应用程序协议》并完成银行账户设置 <mcreference link="https://www.jianshu.com/p/6881cf37723a" index="4">4</mcreference>
- 登录App Store Connect
创建内购产品 - 选择你的应用,进入功能 > 内购或App内购买项目 > 管理 <mcreference link="https://blog.51cto.com/u_16175487/12300853" index="1">1</mcreference><mcreference link="https://www.jianshu.com/p/6881cf37723a" index="4">4</mcreference>
- 点击+ 按钮,选择对应的产品类型(消耗型、非消耗型、订阅等)
- 关键步骤:在产品ID字段中输入自定义标识符(如com.yourcompany.app.productid)
⚠️ 注意:产品ID一旦创建永久不可修改,删除后也无法复用 <mcreference link="https://www.jianshu.com/p/6881cf37723a" index="4">4</mcreference>
- 填写价格、描述等信息并保存
二、客户端代码中的对应位置在你的项目中,产品ID需要与后台配置完全一致: 产品ID定义处(核心位置)
在<mcfile name="InAppPurchaseManager.m" path="g:/code/In-AppPurchaseLiu/ApplePayDemo/InAppPurchase/InAppPurchaseManager.m"></mcfile>中: _productIdentifiers = [NSSet setWithArray:@[@"001Liu", @"002Liu", @"003Liu"]];这里的001Liu等字符串必须与App Store Connect中配置的产品ID完全匹配 产品请求处
在<mcfile name="ViewController.m" path="g:/code/In-AppPurchaseLiu/ApplePayDemo/ViewController.m"></mcfile>中: NSSet *productIdentifiers = [NSSet setWithArray:@[@"001Liu", @"002Liu", @"003Liu"]];[[InAppPurchaseManager sharedManager] requestProductsWithIdentifiers:productIdentifiers];
三、最佳实践与注意事项四、配置示例对照后台配置项 客户端代码对应位置 示例值
产品ID InAppPurchaseManager.m 初始化数组 com.liu.app.premium
价格等级 无需代码配置(由App Store返回) 6元(中国区价格等级1)
产品类型 代码中通过购买逻辑区分(无需硬编码) 非消耗型
|
|
|
|
|