if(image != nil){
mediaSize = String(image!.size.width) + "|" + String(image!.size.height)
}
结果应该是这样的"400|300"
我收到错误:No exact matches in call to initializer
image
是UIImage
,我在尝试将大小转换为字符串之前将其上传到服务器,并且它是有效的
关于此问题的其他问题没有帮助
根据此data
文档,我正在尝试使用以下字段:
$fields = [
'message' => [
'token' => $deviceToken,
'notification' => [
'title' => $notifTitle,
'body' => $notifDesc
],
'data' => $data
]
];
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/bla/messages:send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch) . '<br><br>';
print($result);
其中$data
包含以下内容:
array(11) {
["title"]=>
string(21) "Antwort auf Kommentar"
["msg"]=>
string(29) "Cornholio hat dir geantwortet"
["image"]=>
string(12) "30321555.jpg"
["notifType"]=>
string(5) "reply"
["channelID"]=>
string(21) "channel_reply_comment"
["memeID"]=>
int(20202)
["memeTitle"]=>
string(10) "meme title"
["meme"]=>
string(19) "TrlNO38.mp4"
["size"]=>
string(7) "460|818"
["commentCount"]=>
int(7)
["mentioned"]=>
int(1)
}
我收到此错误:
{ “错误”:{ “代码”:400, “消息”:“'message.data[5].value'(TYPE_STRING)处的值无效,20202 \ n'message.data[9].value'(TYPE_STRING)处的值无效,7 \ n'message.data[10].value'(TYPE_STRING)处的值无效,1“,”status“:”INVALID_ARGUMENT“,”详细信息“:[{ “@type”:“type.googleapis.com/google.rpc.BadRequest”, “fieldViolations”:[{ “field”:“message.data[5].value”, “description”:“'message.data[5].value'(TYPE_STRING)处的值无效,20202” },{ “field”:“message.data[9].value”, “description”:“'message.data[9].value'(TYPE_STRING)处的值无效, 7” }, { “field”:“message.data[10].value”, “description”:“‘message.data[10].value’ (TYPE_STRING) 处的值无效,1” } ] } ] } }
我能够使用旧的 API 发送这样的数据,但是如何使用当前的 API 来发送这样的数据呢?
我正在尝试弄清楚如何使用 PHP 向 Android 设备发送推送通知。
我已在多个网站上查找过它,这是我最后一次尝试:
function sendFCM($registrationIds, $notifTitle, $notifDesc, $notifChannel, $data) {
$client = new Google_Client();
$client->setAuthConfig('bla.json');
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
$client->refreshTokenWithAssertion();
$token = $client->getAccessToken();
$accessToken = $token['access_token'];
$headers = array (
'Authorization: Bearer ' . $accessToken,
'Content-Type:application/json'
);
$notification = array
(
"title" => $notifTitle,
"body" => $notifDesc,
"icon" => "ic_logo_circle",
"android_channel_id" => $notifChannel
);
$fields = array
(
'notification' => $notification,
'data' => $data,
'registration_ids' => $registrationIds
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/projectname/messages:send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
print($result);
curl_close($ch);
}
$notifData = array(
"title" => "this is the title",
"msg" => "the desc",
"image" => "whatever.jpg"
);
sendFCM($registrationIds, "Antwort auf Kommentar", "Cornholio hat dir geantwortet", "channel_reply_comment", $notifData);
$registrationIds
包含多个 Android 设备令牌的数组
{ “错误”:{ “代码”:400,“消息”:“收到无效的 JSON 负载。未知名称“通知”:找不到字段。\ n收到无效的 JSON 负载。未知名称“数据”:找不到字段。\ n收到无效的 JSON 负载。未知名称“registration_ids”:找不到字段。“,”status“:“INVALID_ARGUMENT”,“详细信息”:[{“@type”:“type.googleapis.com/google.rpc.BadRequest”,“fieldViolations”:[{“描述”:“收到无效的 JSON 负载。未知名称“通知”:找不到字段。“},{“描述”:“收到无效的 JSON 负载。未知名称“数据”:找不到字段。“},{“描述”:“收到无效的 JSON 负载。未知名称“registration_ids”:找不到字段。“}]}]}
PhotosPicker(selection: $selectedItem, matching: .videos){
Image(systemName: "camera.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 20)
.padding(2)
}
.onChange(of: selectedItem) { newItem in
videoURL = nil
Task {
if let data = try? await newItem?.loadTransferable(type: Data.self) {
let bytes = Double(data.count)
let megabytes = bytes / (8 * 1024 * 1024)
print("size:")
print(megabytes)
if(megabytes > 32){
print("too big")
}else{
let tempFile = TemporaryMediaFile(withData: data)
let asset = tempFile.avAsset
let vidWidth = await asset?.naturalSize()?.width
let vidHeight = await asset?.naturalSize()?.height
videoHeight = 160 * (vidHeight! / vidWidth!)
videoURL = tempFile.url
}
}else{
print("picking failed")
}
}
}
我明白了
如果“任务”上没有类型注释,则表达式类型不明确
如何修复?
在 MainView 中,我在 NaviationStack 下方有以下内容:
.navigationDestination(for: String.self){ selection in
if(selection == "login"){
Login()
}else if(selection == "register"){
CreateAccount()
}
}
在子视图中,我有这个:
NavigationLink(value: "login"){
Image(systemName: "person.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: profImgSize)
.foregroundColor(Color(UIColor(named: "IconColor")!))
}
当我点击它时,我得到:
注意:链接在任何周围的 NavigationStack 中搜索目的地,然后在 NavigationSplitView 的同一列中搜索。
NavigationLink 显示“String”类型的值,但从链接位置看不到匹配的 navigationDestination 声明。链接无法激活。
当我创建一个最小的示例时,它就可以工作,而当我将所有代码发布到此处时,那就太多了。这里可能有什么问题?
struct Toolbar: View {
let closeThisView: () -> Void?
var toolbarTitle: String
var body: some View {
Text("bla")
}
}
struct Toolbar_Previews: PreviewProvider {
static var previews: some View {
Toolbar(closeThisView: nil, toolbarTitle: "comments")
.preferredColorScheme(.dark)
}
}
nil
既然我在预览中不需要它,我怎样才能传递它或任何函数?就像这就是我也尝试过的:
struct Toolbar_Previews: PreviewProvider {
@Environment(\.dismiss) var dismiss
func closeThisView(){
DispatchQueue.main.async {
self.dismiss()
}
}
static var previews: some View {
Toolbar(closeThisView: closeThisView, toolbarTitle: "comments")
.preferredColorScheme(.dark)
}
}
我正在尝试从购买中获取productId:
private fun queryPurchases(purchases: List<Purchase>){
for (purchase in purchases) {
Log.d("pikaboo", purchase.toString())
when (purchase.purchaseState) {
Purchase.PurchaseState.PURCHASED -> {
val purchaseTime = (purchase.purchaseTime / 1000).toInt()
when (purchase.productId) {
"no_ads_in_app_month" -> {
}
"no_ads_in_app_3_months" -> {
}
}
}
}
}
}
这是日志:
Purchase. Json: {"orderId":"GPA.333.333.333","packageName":"de.bla.foo","productId":"no_ads_in_app_3_months","purchaseTime":1694810217354,"purchaseState":0,"purchaseToken":"xxxxxxxxxxxx","quantity":1,"acknowledged":true}
在是productId
_purchase.productId
Unresolved reference
其他一切都像purchase.purchaseTime
purchase.purchaseState
purchase.packageName
作品一样。
为什么不呢purchase.productId
?这是一个错误吗?怎么解决这个问题呢?