IOS project social sharing-WeChat sharing, circle of friends sharing, and ios circle of friends

Source: Internet
Author: User

Social sharing of iOS projects-sharing, circle of friends, and ios circle of friends

I only share text and images.


1. TARGETS-Info-URL Types

Identifier-> weixin

URL Schemes-> Application id


2. Introduce the header file in AppDelegate. h.

<Pre name = "code" class = "objc"> # import "WXApi. h "{/*** WXSceneSession sharing to session * WXSceneTimeline sharing to friends * WXSceneFavorite sharing to my favorites */enum WXScene _ scene ;}

 
 

3. In AppDelegate. m

-(Id) init {if (self = [super init]) {_ scene = WXSceneSession;} return self ;}- (void) changeScene :( NSInteger) scene {_ scene = scene;}-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// other code // register the application ID with the application ID [WXApi registerApp: @ "xxooxoxoxoxoxo"];} # pragma mark-rewrite the handleOpenURL and openURL method of AppDelegate-(BOOL) application :( UIApplication *) application handleOpenURL :( NSURL *) url {return [WXApi handleOpenURL: url delegate: self];}-(BOOL) application :( UIApplication *) application openURL :( NSURL *) url sourceApplication :( NSString *) sourceApplication annotation :( id) annotation {return [WXApi handleOpenURL: url delegate: self];}
// <Span style = "font-family: Arial, Helvetica, sans-serif;"> onReq and </span> <span style = "font-family: Arial, Helvetica, sans-serif; "> onResp can be left empty </span> <span style =" font-family: Arial, Helvetica, sans-serif; "> </span>-(void) onReq :( BaseReq *) req {if ([req isKindOfClass: [GetMessageFromWXReq class]) {// request the App to provide content, if the app needs to provide the content, use sendRsp to return NSString * strTitle = [NSString stringWithFormat: @ "request the App to provide the content"]; NSString * strMsg = @ "request the App to provide the content, the App calls sendResp: alert and returns it to "; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: strTitle message: strMsg delegate: self cancelButtonTitle: @" OK "otherButtonTitles, nil]; alert. tag = 1000; [alert show]; [alert release];} else if ([req isKindOfClass: [empty class]) {ShowMessageFromWXReq * temp = (ShowMessageFromWXReq *) req; WXMediaMessage * msg = temp. message; // display the passed content WXAppExtendObject * obj = msg. mediaObject; NSString * strTitle = [NSString stringWithFormat: @ "request App display content"]; NSString * strMsg = [NSString stringWithFormat: @ "title: % @ \ n content: % @ \ n Incidental information: % @ \ n thumbnail: % u bytes \ n ", msg. title, msg. description, obj. extInfo, msg. thumbData. length]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: strTitle message: strMsg delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil]; [alert show] [alert release];} else if ([req isKindOfClass: [LaunchFromWXReq class]) {// NSString * strTitle = [NSString stringWithFormat: @ ""]; NSString * strMsg = @ "this is the start message"; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: strTitle message: strMsg delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil]; [alert show]; [alert release] ;}}- (void) onResp :( BaseResp *) resp {if ([resp isKindOfClass: [SendMessageToWXResp class]) {NSString * strTitle = [NSString stringWithFormat: @ "Send media message result"]; NSString * strMsg = [NSString stringWithFormat: @ "errcode: % d", resp. errCode]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: strTitle message: strMsg delegate: self cancelButtonTitle: @ "OK" failed: nil, nil]; [alert show]; [alert release] ;}}




4. This is a good way to share text or images in sessions and moments.

You can call it directly.


# Pragma mark-, share with friends # pragma mark text sharing-(void) sharedByWeChatWithText :( NSString *) WeChatMessage sceneType :( int) sceneType {SendMessageToWXReq * req = [[[SendMessageToWXReq alloc] init] autorelease]; req. text = WeChatMessage; req. bText = YES; req. scene = sceneType; [WXApi sendReq: req] ;}# pragma mark image sharing-(void) sharedByWeChatWithImage :( NSString *) imageName sceneType :( int) sceneType {WXMediaMessage * message = [WXMediaMessage message]; [message setThumbImage: [UIImage imageNamed: imageName]; WXImageObject * ext = [WXImageObject object]; NSString * filePath = [[NSBundle mainBundle] pathForResource: imageName ofType: @ "png"]; ext. imageData = [NSData dataWithContentsOfFile: filePath]; UIImage * image = [UIImage imageWithData: ext. imageData]; ext. imageData = UIImagePNGRepresentation (image); message. mediaObject = ext; SendMessageToWXReq * req = [[[SendMessageToWXReq alloc] init] autorelease]; req. bText = NO; req. message = message; req. scene = sceneType; [WXApi sendReq: req];}


 

 






Questions about social sharing

The other code may not have much problem. I think of a possible problem. You try to run it and unplug the USB cable and run the application again on your mobile phone. The reason is that there is a problem in the debug of the sdk... I think I 've been stuck here for a long time ,...

Why do I share my moments with mengtu by using the tucao artifact? Why can't I open my own moments?

I am also an IOS6 system, and I can't see it for nine times. It seems that the sharing was successful, but it was not accepted at all... This is a conflict with IOS6. The last time I asked the team, they replied to me that there are still problems, and I am very sorry for the inconvenience...
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.