B4i Library iQBImagePicker - Multiple selection image picker

CaptKronos

Active Member
Licensed User
This is a wrapper for QBImagePicker https://github.com/questbeat/QBImagePicker, an image picker that provides for multiple image and video selection.

The wrapper includes helper functions which are primarily to copy the selected assets to a folder on the device but a few others have been included since I required them.

I have noticed that on the Simulator only local (in the DCIM folder) assets can be copied (not sure why) but on a real device I haven't noticed that limitation.

The list of PHAssetCollectionSubtypes (one or more of which are passed to the load function) can be found here https://github.com/mstg/iOS-full-sd...eworks/Photos.framework/Headers/PhotosTypes.h

Installation instructions (modified one of Alberto Iglesias' posts since I haven't tried the MAC HOSTED approach):

- Unzip QBImagePicker.zip into the folder "Libs" in your MAC or in your MAC HOSTED by AnywhereSoftware, normally in "B4i-MacServer\Libs" folder. This will result in iQBImagePicker.h, libiQBImagePicker.a and the folder QBImagePicker.framework being copied to the "Libs" folder.

-Copy the iQBImagePicker.xml to your custom libraries folder in B4i

-If you wish to upload an app using iQBImagePicker to the App Store you will need to replace the file Libs\QBImagePicker.framework\QBImagePicker with the file in QBImagePickerARM.zip. The version of QBImagePicker in the zip only contains the ARM architectures. If you don't replace the file, the submission will be rejected by Apple due to the framework having unsupported architectures (i.e. X86).

iQBImagePicker

Author:
CaptKronos
Version: 1.0
    • QBImagePicker
      • iQBImagePicker.h iQBImagePicker Created by CaptKronos on 14/03/2019.
    • Events:
      • cancelled
      • picked (assets As List)
    • Functions:
      • convertPHAssetToImage (thePHAsset As PHAsset*) As UIImage*
        dim bmp as bitmap = aQBImagePicker.ConvertPHAssetToImage(assets.Get(i))
      • copyPHAssetToFile (ThePHAsset As PHAsset*, destination As NSString*)
        aQBImagePicker.CopyPHAssetToFile(assets.Get(i), "filename")
      • createAlbum (albumName As NSString*) As BOOL
        aQBImagePicker.createAlbum("myalbum") 'if myalbum already exists another album of the same name will be created
      • existsAlbum (albumName As NSString*) As BOOL
        aQBImagePicker.existsAlbum("myalbum") 'returns true if myalbum exists
      • getImageDataFromAsset (thePHAsset As PHAsset*) As NSDictionary*
        Be very careful with this one. Depending on which key you inspect, it can crash your app.
        Dim dict As Object, dictMap As Map
        dict=QBImagePicker.getImageDataFromAsset(assets.Get(0))
        dictMap=NSDictionaryToMap(dict)
        Log(dictMap.Get("PHImageFileUTIKey"))
      • getImageURLFromAsset (thePHAsset As PHAsset*) As NSString*
        Dim url As String=QBPicker.getImageURLFromAsset(assets.Get(i))
        url=url.SubString(7) 'convert to regular path and filename
      • initialize (bi As B4I*, eventName As NSString*)
        Initialises the picker.
        Example:aQBImagePicker.initialize("qbimagepicker")
      • load (myViewController As UIViewController*, mediaType As Int, subType As NSArray*, multiSelect As BOOL, minNumber As Int, maxNumber As Int, numColsInPortrait As Int, numColsInLandscape As Int, useiCloud As BOOL)
        Displays the picker.
        MyViewController: The page to host the picker
        MediaType: 1 - images; 2 - videos; 0 - any
        SubType: a list of PHAssetCollectionSubtypes - see below for the values or pass a list of one item, -1, to select all types
        github.com/mstg/iOS-full-sdk/blob/master/iPhoneOS9.3.sdk/System/Library/Frameworks/Photos.framework/Headers/PhotosTypes.h
        MultiSelect: True - allows more than one asset to be selected
        MinNumber: The minimum number of assets that must be selected
        MaxNumber: The maximum number of assets that can be selected
        NumColsInPortrait: The number of assets to display horizontally when in portrait (0 for default value)
        NumColsInLandscape: The number of assets to display horizontally when in landscape (0 for default value)
        useiCloud: True - will display assets on iCloud
        Example:
        aQBImagePicker.load(pg, 1, subType, True, 1, 100, 0, 0, True)
      • saveImageFileToAlbum (albumName As NSString*, imageURL As NSString*) As BOOL
        aQBImagePicker.saveImageFileToAlbum("myalbum", File.Combine(File.DirDocuments,"myimage.jpg"))
      • saveImageToAlbum (albumName As NSString*, image As UIImage*) As BOOL
        aQBImagePicker.saveImageToAlbum("myalbum", bmp)
      • saveVideoFileToAlbum (albumName As NSString*, videoURL As NSString*) As BOOL
        aQBImagePicker.saveVideoFileToAlbum("myalbum", File.Combine(File.DirDocuments,"myvideo.mp4"))

Usage:
B4X:
Dim aQBImagePicker As QBImagePicker
Dim subType As List
subType.Initialize
subType.Add(201)
aQBImagePicker.initialize("QBImagePicker")
aQBImagePicker.load(Page1,1,subType,True,0,10,0,0,True)

Sub QBImagePicker_picked (assets As List)
    For i=0 To assets.Size-1
        QBPicker.CopyPHAssetToFile(assets.Get(i), destFilname)
    Next
End Sub
 

Attachments

Last edited:

CaptKronos

Active Member
Licensed User
I have updated the iQBImagePicker zip with the github pull requests #21, 215 and 216. A few more language translations are now included but the main change is better handling of images residing on iCloud.
 

CaptKronos

Active Member
Licensed User
Just submitted my first app and received a rejection from Apple due to the QBImagePicker framework having x86 binaries. I have updated the instruction in the OP to address this issue.
 

ilan

Expert
Licensed User
hi, i am trying to use your lib but i am getting an error when i compile. i am using a local mac and copied the framework library + .h and .a file to my local mac and tried to build the app but its not working. i also tried to change the iQBImagePicker file with the one in the arm zip but also error. i also tried to use the hosted builder but no luck.

can you please help me? i really would like to use this lib, thanx :)
 

Attachments

CaptKronos

Active Member
Licensed User
Hi, not sure how I managed to upload the framework with the hardcoded path since that line had been commented out in the version I have been using. Anyway, I have uploaded a new version from Jan this year. Let me know how you get on.
 

CaptKronos

Active Member
Licensed User
I assume you tested with a local Mac rather than the hosted builder. Are you sure you replaced the Framework files on your Mac?

I'll get back to this issue tomorrow.
 

ilan

Expert
Licensed User
I assume you tested with a local Mac rather than the hosted builder. Are you sure you replaced the Framework files on your Mac?

I'll get back to this issue tomorrow.
yes i have a local mac and i replaced all files and the folders in my mac/server/lib folder. i downloaded the 2 new zip's in the first post and replaced all files on my local mac.
i also tried to use the simulator but no luck, i also tried to use the non arm file but no luck. same error as with the previous version.

I'll get back to this issue tomorrow.
thank you very much, i really appreciate your help :)
 

CaptKronos

Active Member
Licensed User
Ok, I found where the hardcoded path was hiding - in the .h file. Again, no idea why I was messing about with hardcoded paths but I'm sure there must have been a good reason! I have updated the iQBImagePicker with the new .h version.
 

ilan

Expert
Licensed User
unfortunately, it is still not working. i tried with the arm file and with the original file that is in the framework folder (QBImagePicker)
both do not work. same error message.

what I did was deleting the whole framework directory in my local builder lib folder + .a & .h file. then replaced with the 2 zips in the first post and try to compile (also restarted b4i) but no luck :(
 

CaptKronos

Active Member
Licensed User
Sure, I'll put something together but I don't think it will help because the error is related to the library itself rather than how you are using it. Though, are you sure you are getting the same message? The error was:
B4X:
/Users/ilantetruashvili/Downloads/macserver65/Libs/iQBImagePicker.h:10:9: fatal error: '/Users/bob/Documents/xcode/iQBImagePicker/Frameworks/QBImagePicker.framework/Headers/QBImagePicker.h' file not found
#import "/Users/bob/Documents/xcode/iQBImagePicker/Frameworks/QBImagePicker.framework/Headers/QBImagePicker.h"
That #import line should no longer exist in iQBImagePicker.h.

I'm going to install the latest B4i beta and take the opportunity to create the Builder's Libs folder from scratch to see if I can replicate the problem.
 
Top