您的位置:首页 > 移动开发 > 微信开发

【iOS知识学习】_iPhone学习微信分享到好友/短信

2015-05-11 19:01 405 查看
导入部分看文档

1.//分享到微信初始化

Appdelegate.m

   //1.初始化ShareSDK应用,字符串"iosv1101"是应该换成你申请的ShareSDK应用中的Appkey
    [ShareSDKregisterApp:@"iosv1101"];

    /**
     连接微信应用以使用相关功能,此应用需要引用WeChatConnection.framework和微信官方SDK
    http://open.weixin.qq.com上注册应用,并将相关信息填写以下字段
     **/
    [ShareSDKconnectWeChatWithAppId:@"wx4868b35061f87885"
                          appSecret:@"64020361b8ec4c99936c0e3999a9f249"
                          wechatCls:[WXApiclass]];

2.//分享到微信好友的事件
- (IBAction)weixinClick:(id)sender
{
   //分享
   NSString *imagePath = [[NSBundlemainBundle]
pathForResource:@"ShareSDK"ofType:@"jpg"];
    
   //1、构造分享内容
   id<ISSContent> publishContent = [ShareSDKcontent:self.contentStr
                                      defaultContent:@"默认内容"
                                               image:[ShareSDKimageWithPath:imagePath]
                                               title:@"ShareSDK"
                                                 url:@"http://www.mob.com"
                                         description:NSLocalizedString(@"TEXT_TEST_MSG",@"这是一条测试信息")
                                           mediaType:SSPublishContentMediaTypeText];
    [ShareSDKclientShareContent:publishContent//内容对象
                           type:ShareTypeWeixiSession//平台类型
                  statusBarTips:YES
                         result:^(ShareType type,SSResponseState
state, id<ISSPlatformShareInfo> statusInfo,id<ICMErrorInfo> error,BOOL
end){//返回事件
                              
                             if (state ==
SSPublishContentStateSuccess)
                              {
                                 NSLog(NSLocalizedString(@"TEXT_SHARE_SUC",@"分享成功!"));
                              }
                             else
if (state ==SSPublishContentStateFail)
                              {
                                 NSLog(NSLocalizedString(@"TEXT_SHARE_FAI",@"分享失败!"),
[error errorCode], [errorerrorDescription]);
                                 NSLog(@"%ld",(long)[errorerrorCode]);
                              }
                              
                          }];
}

3.URLType 写注册时的iosv1101(注意真机测试)

1.//分享到短信平台

Appdelegate.m

//连接短信分享
     [ShareSDKconnectSMS];
2.//发送短信
- (IBAction)duanxinClick:(id)sender
{
   
//分享
   
NSString *imagePath = [[NSBundlemainBundle]
pathForResource:@"ShareSDK"ofType:@"jpg"];
    
   
//1、构造分享内容
   
id<ISSContent> publishContent = [ShareSDKcontent:self.contentStr
                                      
defaultContent:@"默认内容"
                                               
image:[ShareSDKimageWithPath:imagePath]
                                               
title:@"ShareSDK"
                                                 
url:@"http://www.mob.com"
                                         
description:NSLocalizedString(@"TEXT_TEST_MSG",@"这是一条测试信息")
                                           
mediaType:SSPublishContentMediaTypeText];
    [ShareSDKclientShareContent:publishContent//内容对象
                           
type:ShareTypeSMS//平台类型
                  
statusBarTips:YES
                         
result:^(ShareType type,SSResponseState state,
id<ISSPlatformShareInfo> statusInfo,id<ICMErrorInfo> error,BOOL
end) {//返回事件
                              
                             
if (state ==SSPublishContentStateSuccess)
                              {
                                 
NSLog(NSLocalizedString(@"TEXT_SHARE_SUC",@"分享成功!"));
//                                  [self.navigationController popViewControllerAnimated:YES];
                              }
                             
elseif (state ==
SSPublishContentStateFail)
                              {
                                 
NSLog(NSLocalizedString(@"TEXT_SHARE_FAI",@"分享失败!"), [error
errorCode], [errorerrorDescription]);
//                                  [self.navigationController popViewControllerAnimated:YES];
                              }
                          }];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: