AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-10642456

Eduard Unruh's questions

Martin Hope
TheGreatCornholio
Asked: 2025-03-03 04:38:14 +0800 CST

MySQL - 警告:#1365 除以 0

  • 7

我正在使用这个查询:

UPDATE memes SET upvotes = upvotes + 1, score = ROUND((upvotes * 100) / (upvotes + downvotes)) WHERE ((mature_upvotes / upvotes) * 100) < 15 AND upvotes > 8 AND upvotes < 13

我收到警告

Warning: #1365 Division by 0

有超过 10k 行,所以我不知道哪些受到了影响。但是,当 (upvotes + downvotes)永远不会为 0 时,这怎么可能呢?

我还更新了特定的一行,mature_upvotes看看0是否会引起警告,但我没有得到它

mysql
  • 1 个回答
  • 61 Views
Martin Hope
TheGreatCornholio
Asked: 2024-11-29 03:34:58 +0800 CST

快速尝试错误:条件绑定的初始化程序必须具有可选类型,而不是

  • 0
if let tenorReceived = try JSONDecoder().decode([TenorModel].self, from: responseString){
    

}

我收到错误Initializer for conditional binding must have Optional type, not '[TenorModel]'

如何解决这个问题?

我必须使用try而不是try?这样我才能捕获错误,如何做到这一点?

swift
  • 2 个回答
  • 54 Views
Martin Hope
TheGreatCornholio
Asked: 2024-11-19 19:55:32 +0800 CST

将 UIImage.size 转换为字符串

  • 3
if(image != nil){
    mediaSize = String(image!.size.width) + "|" + String(image!.size.height)
}

结果应该是这样的"400|300"

我收到错误:No exact matches in call to initializer

image是UIImage,我在尝试将大小转换为字符串之前将其上传到服务器,并且它是有效的

关于此问题的其他问题没有帮助

  • 2 个回答
  • 33 Views
Martin Hope
TheGreatCornholio
Asked: 2024-09-05 02:12:39 +0800 CST

使用 PHP 将推送通知数据发送到 Android

  • 6

根据此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 来发送这样的数据呢?

  • 1 个回答
  • 55 Views
Martin Hope
TheGreatCornholio
Asked: 2024-09-03 23:31:24 +0800 CST

使用 PHP 向 Android 设备发送推送通知

  • 6

我正在尝试弄清楚如何使用 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”:找不到字段。“}]}]}

  • 1 个回答
  • 46 Views
Martin Hope
TheGreatCornholio
Asked: 2024-08-03 07:18:54 +0800 CST

任务错误:表达式类型不明确,没有类型注释

  • 5
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")
        }
    }
}

我明白了

如果“任务”上没有类型注释,则表达式类型不明确

如何修复?

swift
  • 1 个回答
  • 69 Views
Martin Hope
TheGreatCornholio
Asked: 2024-05-04 05:56:51 +0800 CST

NavigationStack - NavigationLink 不起作用

  • 5

在 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 声明。链接无法激活。

当我创建一个最小的示例时,它就可以工作,而当我将所有代码发布到此处时,那就太多了。这里可能有什么问题?

  • 1 个回答
  • 23 Views
Martin Hope
Eduard Unruh
Asked: 2023-11-28 06:40:55 +0800 CST

SwiftUI - PreviewProvider 为可选的 Void 函数传递 nil

  • 5
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)
    }
}
swift
  • 2 个回答
  • 36 Views
Martin Hope
Eduard Unruh
Asked: 2023-09-19 23:16:52 +0800 CST

Android Kotlin - 计费 - 从应用内购买获取productId

  • 6

我正在尝试从购买中获取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.productIdUnresolved reference

其他一切都像purchase.purchaseTime purchase.purchaseState purchase.packageName作品一样。

为什么不呢purchase.productId?这是一个错误吗?怎么解决这个问题呢?

android
  • 1 个回答
  • 16 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve