iOS學習,ios學習吧

來源:互聯網
上載者:User

iOS學習,ios學習吧

準備工作---原文來自這個

首先要在開放平台申請 AppID(我第一天晚上申請的,第二天中午就通過了),接著匯入 SDK,也就是3個 .h 和一個 .a 檔案,詳情見這裡

如果你是 copy 在自建 group 裡面,

1.需要在 Build Phases - Link Binary With Libraries 裡面 .a 檔案

2.在 Copy Bundle Resources add .h 檔案

3.在 Bulid Settings - Library Search Paths "+" sdk 路徑

如果 copy 在內建 group 裡面,則不需要,已經自動設定好

AppDelegate.h ,import "WXApi.h" 和 遵守協議

#import <UIKit/UIKit.h>#import "WXApi.h"@interface AppDelegate : UIResponder <UIApplicationDelegate,WXApiDelegate>@property (strong, nonatomic) UIWindow *window;@end

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //申請的 AppID    [WXApi registerApp:@"wxxxxx"];    return YES;}//重寫 handleOpenURL-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{    return [WXApi handleOpenURL:url delegate:self];}//重寫 openURL-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{    return [WXApi handleOpenURL:url delegate:self];}

在你需要引用的類裡面

#import "ViewController.h"#import "WXApi.h"@interface ViewController ()@property (nonatomic,strong)UIButton *button;@end@implementation ViewControllerstatic NSString *KLinkURL = @"http://www.iqiyi.com/a_19rrhbkfv1.html?vfm=2008_aldbd";static NSString *KLinkTagName = @"WECHAT_TAG_JUMP_SHOWRANK";static NSString *KLinkTitle = @"史上最帥男人";static NSString *KLinkDescription = @"媽呀,誰都別攔我,我要嫁給他!!!!!!!!";- (void)viewDidLoad {    [super viewDidLoad];    [self.view addSubview:self.button];}-(void)Click{    //建立發送對象執行個體    SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];    sendReq.bText = NO;//不使用文本資訊    sendReq.scene = 0;//0 = 好友名單 1 = 朋友圈 2 = 收藏        //建立分享內容對象    WXMediaMessage *urlMessage = [WXMediaMessage message];    urlMessage.title = KLinkTitle;//分享標題    urlMessage.description = KLinkDescription;//分享描述     [urlMessage setThumbImage:[UIImage imageNamed:@"sb2.jpg"]];//分享圖片,使用SDK的setThumbImage方法可壓縮圖片大小,圖片大小不能超過 32 KB        //建立多媒體對象    WXWebpageObject *webObj = [WXWebpageObject object];    webObj.webpageUrl = KLinkURL;//分享連結        //完成發送對象執行個體    urlMessage.mediaObject = webObj;    sendReq.message = urlMessage;        //發送分享資訊    [WXApi sendReq:sendReq];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}-(UIButton *)button{    if (!_button) {        _button = [[UIButton alloc]init];        _button.frame = CGRectMake(100, 100, 100, 100);        _button.backgroundColor = [UIColor redColor];        [_button addTarget:self action:@selector(Click) forControlEvents:UIControlEventTouchUpInside];    }    return _button;}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.