小编Mr.*_*ean的帖子

使用Alamofire在swift上传多个图像

我正在使用以下代码将单个图像上传到服务器:

private static func urlRequestWithComponents(urlString:String, parameters:Dictionary<String, String>, imageData:NSData?, imageName: String) -> (URLRequestConvertible , NSData) {

    // create url request to send
    let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!)
    mutableURLRequest.HTTPMethod = Alamofire.Method.POST.rawValue
    let boundaryConstant = "myRandomBoundary12345";
    let contentType = "multipart/form-data;boundary="+boundaryConstant
    mutableURLRequest.setValue(contentType, forHTTPHeaderField: "Content-Type")


    // create upload data to send
    let uploadData = NSMutableData()
    if(imageData != nil && imageData?.length != 0) {
        // add image
        uploadData.appendData("\r\n--\(boundaryConstant)\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
        uploadData.appendData("Content-Disposition: form-data; name=\"\(imageName)\"; filename=\"\(StringHelper.sharedInstance.randomString(5)).png\"\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
        uploadData.appendData("Content-Type: image/png\r\n\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
        uploadData.appendData(imageData!)
    }
    // add parameters
    for (key, value) in parameters { …
Run Code Online (Sandbox Code Playgroud)

image-uploading ios swift alamofire

16
推荐指数
3
解决办法
2万
查看次数

在 Tableview 单元格上的长按手势上禁用 didSelectRowAtIndexPath

我一直在尝试在 UITableView 上设置一个长按手势识别器。该手势工作正常,但我想在识别出长按手势时禁用 UITableView 的 didSelectRowAtIndexPath 委托功能。

简而言之,如果用户单击单元格,我必须推送一个新的 UIViewController,如果用户长按单元格,我必须显示一个 UIActionSheet。

extension GroupChatListingViewController : UIGestureRecognizerDelegate {

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}

func setupLongPress() {

    longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress))
    longPressGesture.minimumPressDuration = 1.0 // 1 second press
    longPressGesture.delegate = self
    longPressGesture.cancelsTouchesInView = false
    self.tableView.addGestureRecognizer(longPressGesture)
}

func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer) {

    if longPressGestureRecognizer.state == UIGestureRecognizerState.began {

        self.tableView.allowsSelection = false
        let touchPoint = longPressGestureRecognizer.location(in: self.tableView)
        if let indexPath = tableView.indexPathForRow(at: touchPoint) {
            self.showActionSheet()
        }
    }
    else …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uilongpressgesturerecogni

5
推荐指数
1
解决办法
1522
查看次数

使用UIActivityViewController未将多张图像保存在照片库中

我需要在照片库中保存多个图像,用户可以从应用程序库中多次选择图像,然后将它们保存在iPhone照片库中.我正在展示UIActivityViewController这个目的.

假设用户选择10个或更多图像并选择将它们保存到照片库中,则仅保存7-8个图像.

有什么办法可以在没有任何故障的情况下保存照片库中的图像数组吗?

谢谢

let images = Generic.fetchImagesFromMediaFiles(self.selectedMediaObj) // to fetch selected images

let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil);

if let popoverPresentationController = activityViewController.popoverPresentationController {
    popoverPresentationController.sourceView = self.shareAllView
}
Run Code Online (Sandbox Code Playgroud)

uiimage ios uiactivityviewcontroller swift

5
推荐指数
1
解决办法
365
查看次数