How to select multiple picture from galery using GMImagePicker in xamarin IOS?

SreeeeSreeee INMember ✭✭✭✭✭
edited January 14 in Xamarin.Forms

Hi, I am following this blog for selecting multiple pictures from the gallery. For IOS I am Using GMImagePicker for selecting multiple pictures from the gallery.(In the blog suggesting elcimagepicker, but that is not available in Nuget Store now)

I go through the GMImagePicker usage part but didn't find how to add the selected images to List and pass that value in MessagingCenter(like the android implementation). In that usage part only telling about the picker settings. Anyone please give me any sample code for doing this feature?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    I created a sample for iOS part.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @ColeX said:
    I created a sample for iOS part.

    Thanks, I will go through this and update you...

  • SreeeeSreeee INMember ✭✭✭✭✭

    hi, @ColeX One question :)

    string s = Save(UIImage.LoadFromData(data), strs[strs.Length - 1]);          
        MessagingCenter.Send<App, string>((App)Xamarin.Forms.Application.Current, "ImagesSelected", s);
    

    Sending only one picture path by MessagingCenter. Why you avoid List as we use in the android part?

  • SreeeeSreeee INMember ✭✭✭✭✭
    public void SelectedImage()
        {
            var picker = new GMImagePickerController();
            List<string> images = new List<string>();
            picker.FinishedPickingAssets += (sender, args) => {
                foreach (var item in args.Assets)
                {
                    PHImageManager.DefaultManager.RequestImageData(item, null, (NSData data, NSString dataUti, UIImageOrientation orientation, NSDictionary info) => {
                        NSUrl url = info.ObjectForKey(new NSString("PHImageFileURLKey")) as NSUrl;
                        string urlString = url.AbsoluteString;
    
                        string[] strs = urlString.Split("/");
    
                        string filepath = Save(UIImage.LoadFromData(data), strs[strs.Length - 1]);
                        images.Add(filepath);
                    });
                }
                MessagingCenter.Send<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", images);
            };
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(picker, true, null);
        }
    

    Is this work?

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai
    edited January 15

    @Sreeee Because the method PHImageManager.DefaultManager.RequestImageData is executed asynchronously. So MessagingCenter.Send will be called earlier than RequestImageData . So ,when you call the MessagingCenter.Send ,the list still null.

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited January 15

    Hi @ColeX and @Quintán

    When I build the project in Mac getting an error:

    Any casting needed?

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited January 15

    @Sreeee said:
    Hi @ColeX and @Quintán

    When I build the project in Mac getting an error:

    Any casting needed?

    Update: Removed double quotes and add single quotes solved that problem.

    string[] strs = urlString.Split('/');
    
  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    @Sreeee I have downloaded your project and it works fine.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @Quintán said:
    @Sreeee I have downloaded your project and it works fine.

    Did you make any modifications?

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    No , just cleaned and rebuilded the project.

  • IshaPIshaP Member ✭✭

    Hi,

    My app is crashing after iOS 13 update when I tried to use GMImagePicker. It was working fine in the earlier versions. Can anybody suggest me a workaround?

    =================================================================

    Native Crash Reporting

    Got a SIGSEGV while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries

    used by your application.

    =================================================================

    Native stacktrace:

    0x10b2fd985 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_dump_native_crash_info
    0x10b2f18c5 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_native_crash
    0x10b304c01 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_sigsegv_signal_handler_debug
    0x7fff51414b5d - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libsystem_platform.dylib : _sigtramp
    0x10e0e6cf0 - Unknown
    0x10b2f076e - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_exception_internal
    0x10b2ef849 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_exception
    0x10b271659 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : handle_signal_exception
    0x7ffee4d2efa8 - Unknown
    

    =================================================================
    Basic Fault

    Address Reporting

    Memory around native instruction pointer (0x10b3e6a54):0x10b3e6a44 8b 47 1c 5d c3 0f 1f 80 00 00 00 00 55 48 89 e5 .G.]........UH..
    0x10b3e6a54 8b 47 20 a9 00 00 00 02 75 0c a9 00 00 00 10 75 .G .....u......u
    0x10b3e6a64 26 48 8b 07 5d c3 48 8d 3d 89 1f 1f 00 48 8d 35 &H..].H.=....H.5
    0x10b3e6a74 e9 1a 1f 00 48 8d 0d 5d 1b 1f 00 ba 79 03 00 00 ....H..]....y...

    =================================================================

    Managed Stacktrace:

      at <unknown> <0xffffffff>
      at UIKit.UIApplication:UIApplicationMain <0x00251>
      at UIKit.UIApplication:Main <0x000b2>
      at UIKit.UIApplication:Main <0x00132>
      at CS.iOS.Application:Main <0x00092>
    

    at :runtime_invoke_void_object <0x00352>

  • IshaPIshaP Member ✭✭

    Hi,

    My app is crashing after iOS 13 update when I tried to use GMImagePicker. It was working fine in the earlier versions. Can anybody suggest me a workaround?

    =================================================================

    Native Crash Reporting

    Got a SIGSEGV while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries

    used by your application.

    =================================================================

    Native stacktrace:

    0x10b2fd985 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_dump_native_crash_info
    0x10b2f18c5 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_native_crash
    0x10b304c01 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_sigsegv_signal_handler_debug
    0x7fff51414b5d - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libsystem_platform.dylib : _sigtramp
    0x10e0e6cf0 - Unknown
    0x10b2f076e - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_exception_internal
    0x10b2ef849 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : mono_handle_exception
    0x10b271659 - /Users/cs/Library/Developer/CoreSimulator/Devices/40494F30-43C0-4F79-8414-0FD4073DA3FA/data/Containers/Bundle/Application/2520E37A-B0A4-4959-98D2-E75EAFE04663/CS.iOS.app/CS.iOS : handle_signal_exception
    0x7ffee4d2efa8 - Unknown
    

    =================================================================
    Basic Fault

    Address Reporting

    Memory around native instruction pointer (0x10b3e6a54):0x10b3e6a44 8b 47 1c 5d c3 0f 1f 80 00 00 00 00 55 48 89 e5 .G.]........UH..
    0x10b3e6a54 8b 47 20 a9 00 00 00 02 75 0c a9 00 00 00 10 75 .G .....u......u
    0x10b3e6a64 26 48 8b 07 5d c3 48 8d 3d 89 1f 1f 00 48 8d 35 &H..].H.=....H.5
    0x10b3e6a74 e9 1a 1f 00 48 8d 0d 5d 1b 1f 00 ba 79 03 00 00 ....H..]....y...

    =================================================================

    Managed Stacktrace:

      at <unknown> <0xffffffff>
      at UIKit.UIApplication:UIApplicationMain <0x00251>
      at UIKit.UIApplication:Main <0x000b2>
      at UIKit.UIApplication:Main <0x00132>
      at CS.iOS.Application:Main <0x00092>
    

    at :runtime_invoke_void_object <0x00352>

Sign In or Register to comment.