In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how iOS to achieve Wechat to share multiple pictures, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Preface
Wechat shares to moments, the types that can be shared are: text type, picture type, music type, video type and web page type, but when we are doing photo sharing, we find that the API given by Wechat can only share one picture, which can not meet the needs of some APP. While the product dog or Boss wants to share multiple pictures, such as an APP I made some time ago, which is an e-commerce APP, I want to share all the pictures of the products to the moments. The API of Wechat does not provide API at all, so here we can only share it with the iOS system.
UIActivityViewController
UIActivityViewController is supported in iOS 6 and cannot be used in Apple TV development. And UIActivityViewController inherits UIViewController directly, which means we need to present and dissolve the view ourselves.
Main code
OC code
UIImage * imageToShare = [UIImage imageNamed:@ "99687078.jpg"]; UIImage * imageToShare1 = [UIImage imageNamed:@ "2222.jpg"]; NSArray * activityItems = @ [imageToShare,imageToShare1]; UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; [self presentViewController:activityVC animated:TRUE completion:nil]
Swift code
Let imageToShare1 = UIImage.init (named: "99687078.jpg") let imageToShare2 = UIImage.init (named: "2222.jpg") let activityItems = [imageToShare1,imageToShare2] let activityVC = UIActivityViewController.init (activityItems: activityItems, applicationActivities: nil) self.present (activityVC, animated: true, completion: nil)
Be careful
When we share multiple pictures to our moments, we will find that we fail to share multiple pictures directly from mobile albums without doing any processing. I studied the specific reasons and found that the total size of the shared data is limited; here, for example, elevators, the limited weight of elevators is fixed, so no matter how many people you take, the passengers are fatter, then there are fewer passengers, and if the passengers are thinner, you can sit a few more. So when UIActivityViewController shares multiple pictures to moments, I compress the pictures to a specified width and height according to the number of pictures. For example, a picture, I compress it to the same size as the Wechat image. If I compress nine pictures, I compress them to 500mm.
Code
The method of compressing the image is glued out below, where compressibilityFactor is the maximum width and height of the image.
# import "WeChatJPEGImager.h" # define KCompressibilityFactor 1280.00@implementation WeChatJPEGImager#pragma mark-compressing the maximum width and height of an image 1280 is similar to the Wechat algorithm-(UIImage *) getJPEGImagerImg: (UIImage *) image {CGFloat oldImg_WID = image.size.width; CGFloat oldImg_HEI = image.size.height; / / CGFloat aspectRatio = oldImg_WID/oldImg_HEI / / aspect ratio if (oldImg_WID > KCompressibilityFactor | | oldImg_HEI > KCompressibilityFactor) {/ / beyond the set maximum width, first determine which side is the longest if (oldImg_WID > oldImg_HEI) {/ / the width is greater than the height oldImg_HEI = (KCompressibilityFactor * oldImg_HEI) / oldImg_WID; oldImg_WID = KCompressibilityFactor;} else {oldImg_WID = (KCompressibilityFactor * oldImg_WID) / oldImg_HEI; oldImg_HEI = KCompressibilityFactor } UIImage * newImg = [self imageWithImage:image scaledToSize:CGSizeMake (oldImg_WID, oldImg_HEI)]; NSData * dJpeg = nil; if (UIImagePNGRepresentation (newImg) = = nil) {dJpeg = UIImageJPEGRepresentation (newImg, 0.5);} else {dJpeg = UIImagePNGRepresentation (newImg);} return [UIImage imageWithData:dJpeg];} # pragma mark-the maximum width and height of multiple images is 1280 similar to the Wechat algorithm-(NSArray *) getJPEGImagerImgArr: (NSArray *) imageArr {NSMutableArray * newImgArr = [NSMutableArray new]; for (int I = 0) I compressibilityFactor | | oldImg_HEI > compressibilityFactor) {/ / determine which side is the longest if (oldImg_WID > oldImg_HEI) {/ / width is greater than the height oldImg_HEI = (compressibilityFactor * oldImg_HEI) / oldImg_WID; oldImg_WID = compressibilityFactor;} else {oldImg_WID = (compressibilityFactor * oldImg_WID) / oldImg_HEI; oldImg_HEI = compressibilityFactor;} UIImage * newImg = [self imageWithImage:image scaledToSize:CGSizeMake (oldImg_WID, oldImg_HEI)]; NSData * dJpeg = nil If (UIImagePNGRepresentation (newImg) = = nil) {dJpeg = UIImageJPEGRepresentation (newImg, 0.5);} else {dJpeg = UIImagePNGRepresentation (newImg);} return [UIImage imageWithData:dJpeg];} # pragma mark-Custom maximum width and height of multiple images-(NSArray *) getJPEGImagerImgArr: (NSArray *) imageArr compressibilityFactor: (CGFloat) compressibilityFactor {NSMutableArray * newImgArr = [NSMutableArray new]; for (int I = 0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.