4.B 修复:friendsShare 路由跑偏(sharefriend/type 字段兼容 number)
【契约影响】docs/H5-Native-Contract.md §3.1[2]
H5 实际传:{"sharefriend":1, "sharetype":0, "type":2, ...}(number 而非
契约描述的 string "1"/"2")。先前用 obj["sharefriend"]?.asString 只匹配
.string case,遇到 number 全部 fallback 到 "",导致:
- sharefriend = "" → ShareCenter.dispatchSubGame default 分支 →
WechatShare.share(scene: .timeline) → **错走朋友圈**
- type = "" → WechatShare.share else 分支 → **错走链接分享**
实际 H5 意图:sharefriend=1 (好友/弹 SharePanel) + type=2 (截图分享)。
看到的现象:H5 想截图分享给好友,实际成了链接分享到朋友圈。
修复:sharefriend / sharetype / type 改用 asLooseString(number → 整数
字符串,与 commit b058990 修 mediaTypeAudio.user 同款)。对齐原 msext
ObjC 行为:[NSNumber intValue] 与 [NSString intValue] 都得到整数,所以
不论 H5 传 string 还是 number 都能识别。
webpageUrl / title / description 三项 H5 始终传 string,保持 asString
不变。
This commit is contained in:
@@ -54,10 +54,14 @@ public enum FriendsShareHandler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let content = ShareContent(
|
let content = ShareContent(
|
||||||
// 缺失默认空串 → ShareCenter default 分支兜底(与原 msext [nil intValue]==0 等价)
|
// sharefriend / sharetype / type 实际 H5 传 number(如 1/2 而非 "1"/"2"),
|
||||||
sharefriend: obj["sharefriend"]?.asString ?? "",
|
// 必须用 asLooseString 兼容(与 mediaTypeAudio.user 同款问题,commit b058990)。
|
||||||
sharetype: obj["sharetype"]?.asString ?? "",
|
// 对齐原 msext ObjC 行为:[NSNumber intValue] 与 [NSString intValue] 都得到整数。
|
||||||
type: obj["type"]?.asString ?? "",
|
// 用 asString 会拿不到值 → 整路由跑偏到 default 分支。
|
||||||
|
sharefriend: obj["sharefriend"]?.asLooseString ?? "",
|
||||||
|
sharetype: obj["sharetype"]?.asLooseString ?? "",
|
||||||
|
type: obj["type"]?.asLooseString ?? "",
|
||||||
|
// 下面 3 项 H5 始终传 string,保持 asString
|
||||||
webpageUrl: obj["webpageUrl"]?.asString ?? "",
|
webpageUrl: obj["webpageUrl"]?.asString ?? "",
|
||||||
title: obj["title"]?.asString ?? "",
|
title: obj["title"]?.asString ?? "",
|
||||||
desc: obj["description"]?.asString ?? ""
|
desc: obj["description"]?.asString ?? ""
|
||||||
|
|||||||
Reference in New Issue
Block a user