Skip to content

Conversation

YangSen-qn
Copy link
Contributor

No description provided.

Copy link

niupilot bot commented Sep 22, 2025

PR Review: Swift Demo Addition

Reviewing PR #458 that adds a Swift demo project to the repository.

Todo List:

  • Analyze Swift demo project structure and files
  • Review AppDelegate.swift implementation
  • Review ViewController.swift implementation
  • Review SceneDelegate.swift implementation
  • Check Xcode project configuration
  • Identify code quality issues and improvements
  • Provide comprehensive review feedback

@qiniu-prow qiniu-prow bot added the size/XL label Sep 22, 2025
Copy link

Summary of Changes

Hello @YangSen-qn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Swift demonstration application, QiniuDemoSwift, designed to showcase the integration and usage of the Qiniu SDK for image uploading within an iOS environment. The demo provides a user interface to select images from the device's photo library and then initiate an upload process to Qiniu's cloud storage, offering a practical example for developers looking to implement similar functionality in their Swift projects. It replaces or complements an existing Objective-C demo with a modern Swift implementation.

Highlights

  • New Swift Demo Project: A complete new Xcode project named QiniuDemoSwift has been added, providing a modern Swift-based demonstration of Qiniu SDK integration.
  • Qiniu SDK Integration: The demo showcases image upload functionality using the QiniuSDK (via objc-sdk Swift Package Manager dependency), demonstrating how to upload both PHAsset objects and local files.
  • Image Selection: The ZLPhotoBrowser library has been integrated to allow users to select images from their device's photo library, which are then prepared for upload.
  • Xcode Project Structure: All necessary Xcode project files, including project.pbxproj, contents.xcworkspacedata, and QiniuDemoSwift.xcscheme, are included to define the new application's build and runtime configurations.
  • Objective-C Demo Cleanup: An old Objective-C demo workspace file (QiniuDemoOC/QiniuDemo.xcworkspace/contents.xcworkspacedata) has been removed, indicating a shift towards the new Swift demo.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@YangSen-qn YangSen-qn merged commit eb3c6fd into qiniu:master Sep 22, 2025
1 check failed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Swift demo application for the Qiniu SDK. While it's a good starting point, I've identified several critical and high-severity issues that need attention. These include hardcoded placeholder values that will cause the application to fail (e.g., an empty upload token), incorrect configurations such as a hardcoded "zip" mime type for image uploads and an excessively high deployment target, and missing permission descriptions that will lead to runtime crashes on modern iOS versions. My review includes specific code suggestions to resolve these problems and enhance the overall robustness and usability of the demo.

<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The NSPhotoLibraryUsageDescription key's value is empty. Since the app needs to access the photo library to allow users to select images for upload, you must provide a user-facing string explaining why this permission is required. On recent iOS versions, failing to provide this description will cause your app to crash when the photo picker is presented.

	<string>This app needs access to your photo library to select and upload images.</string>

}

@IBAction func upload(_ sender: UIButton) {
let token = ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The upload token is hardcoded as an empty string. This will cause all upload attempts to fail with an authentication error. For this demo to be functional, a valid upload token must be provided. It's recommended to fetch this token from a server at runtime or provide clear instructions on how to obtain and configure a valid token.

Suggested change
let token = ""
let token = "PASTE_YOUR_TOKEN_HERE"

GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.4;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The IPHONEOS_DEPLOYMENT_TARGET is set to 18.4, which is likely a beta or unreleased version of iOS. This will severely limit the devices on which the demo can run. It's recommended to lower this to a more widely adopted version (e.g., 14.0) to ensure the demo is accessible to more users, unless a feature specific to iOS 18.4 is required.

				IPHONEOS_DEPLOYMENT_TARGET = 14.0;

Comment on lines +27 to +29
let option = QNUploadOption.init(mime: "zip", progressHandler: { key, progress in
print("key:\(String(describing: key)) progress:\(progress)")
}, params: nil, checkCrc: false, cancellationSignal: nil);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The mime type is hardcoded to "zip", which is incorrect for image uploads. This can cause problems for server-side processing or when trying to view the uploaded file. You should pass nil to let the SDK attempt to infer the mime type, which is a more robust approach for handling various image formats.

Suggested change
let option = QNUploadOption.init(mime: "zip", progressHandler: { key, progress in
print("key:\(String(describing: key)) progress:\(progress)")
}, params: nil, checkCrc: false, cancellationSignal: nil);
let option = QNUploadOption.init(mime: nil, progressHandler: { key, progress in
print("key:\(String(describing: key)) progress:\(progress)")
}, params: nil, checkCrc: false, cancellationSignal: nil);

Comment on lines +40 to +47
let filePath = Bundle.main.path(forResource: "image.jpg", ofType: nil)
uploader?.putFile(filePath, key: "iOS-demo-test-a", token: token, complete: { (response, key, responseData) in
if response?.isOK == true {
print("upload success:\(String(describing: responseData))")
} else {
print("upload fail:\(String(describing: response))")
}
}, option: option)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block has two issues:

  1. Potential Crash: The path for image.jpg is retrieved from the bundle without checking if it's nil. If the file doesn't exist in the bundle, this will likely lead to a crash when putFile is called. You should use guard let to safely unwrap the path and handle the error case.
  2. Hardcoded Key: The upload key is hardcoded, which means uploads will overwrite the same file. It's better to generate a unique key for each upload to avoid this.
            guard let filePath = Bundle.main.path(forResource: "image.jpg", ofType: nil) else {
                print("Error: image.jpg not found in the project bundle.")
                // TODO: Show an alert to the user.
                return
            }
            let key = "iOS-demo-test-\(UUID().uuidString)"
            uploader?.putFile(filePath, key: key, token: token, complete: { (response, key, responseData) in
                if response?.isOK == true {
                    print("upload success:\(String(describing: responseData))")
                } else {
                    print("upload fail:\(String(describing: response))")
                }
            }, option: option)

ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = W2TP34G2MM;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The DEVELOPMENT_TEAM is hardcoded. This makes it difficult for other developers to build the project, as they would need to manually change this ID to their own. It is recommended to configure this setting to use automatic signing in Xcode, which avoids committing team-specific information to the repository.

<key>NSPhotoLibraryUsageDescription</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string></string>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The NSCameraUsageDescription key's value is empty. The ZLPhotoBrowser library may allow users to take a new photo using the camera. If this functionality is intended to be available, you should provide a user-facing string explaining why camera access is needed. If the app will not use the camera, you can remove this key.

	<string>This app needs access to your camera to take and upload photos.</string>

}, params: nil, checkCrc: false, cancellationSignal: nil);

if asset != nil {
uploader?.put(asset, key: "iOS-demo-test", token: token, complete: { (response, key, responseData) in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The upload key is hardcoded. This will cause every upload to overwrite the same file in your storage bucket. To prevent accidental data loss, it's better to generate a unique key for each upload. A common approach is to use a UUID or a timestamp.

Suggested change
uploader?.put(asset, key: "iOS-demo-test", token: token, complete: { (response, key, responseData) in
uploader?.put(asset, key: "iOS-demo-\(UUID().uuidString)", token: token, complete: { (response, key, responseData) in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant