Fixing Problem UIActivityViewController Share Photo Function Not Working Sometimes

Hello guys, today I got a problem when no errors or warnings message in my IDE (Xcode). It's so confusing for programmer when error happens for no reason. It's like magic we don't know how it happens lol.

When sharing, I use iOS class library UIActivityViewController. It's a feature from iOS when we want to share something on other platforms. Like above image when we want to share something using UIActivityViewController, it will appear popup view dialog like above. You can choose what platform you will want to share.

Basically, UIActivityViewController can provide text and image together. But on some app like Whatsapp, it only applies image or text not both. I have shared the trick to avoid always sharing text when we want to share image.

There's a problem when you share image large, like 3MB that I tested. It will show no error but it doesnt share the image. It's weird for the first time because you don't know what happen. So thank GOD I found the issue, you need to resize it to below 1MB I think. So share function will work as we want.

I share the code below how I compressed the image, but firstly you need to check if your image is below 1MB or not. If the image is more than 1MB, it will compress the image. You don't need a library to compress. There's function in iOS you have to compress it.

You can see code above, it's a part of sharing in UIActivityViewController. I don't share full code, that I know you will get it on google. It's simple but I hope it can help you to solve the problem. Thanks for visiting my simple blog, have a nice day. Thanks.

Popular posts from this blog

How to restart the app with flutter Android and iOS

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Missing system image Android Studio solution