1
2
3
4
5
6
7
|
//TencentOpenapi
#
import
<
TencentOpenAPI
/
TencentOAuth
.h>
#
import
<
TencentOpenAPI
/
QQApiinterface
.h>
#
import
<
TencentOpenAPI
/
QQApiInterfaceObject
.h>
#
import
<
TencentOpenAPI
/sdkdef.h>
#
import
<
TencentOpenAPI
/
TencentmessageObject
.h>
#
import
<
TencentOpenAPI
/
TencentOAuthObject
.h>
|
1
2
3
4
5
|
//重写openURL
func
application(_ app:
UIApplication
, open url:
URL
,
options: [
UIApplicationOpenURLOptionsKey
:
Any
] = [:]) ->
Bool
{
return
TencentOAuth
.handleOpen(url)
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
key
>NSAppTransportSecurity
key
>
<
dict
>
<
key
>NSAllowsArbitraryLoads
key
>
<
true
/>
dict
>
<
key
>LSApplicationQueriesSchemes
key
>
<
array
>
<
string
>mqqwpa
string
>
<
string
>mqqopensdkapiV3
string
>
<
string
>wtloginmqq2
string
>
<
string
>mqzone
string
>
<
string
>mqqopensdkapiV2
string
>
<
string
>mqqapi
string
>
<
string
>mqq
string
>
array
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import
UIKit
class
ViewController
:
UIViewController
{
var
_tencentOAuth:
TencentOAuth
!
override
func
viewDidLoad() {
super
.viewDidLoad()
_tencentOAuth =
TencentOAuth
.
init
(appId:
"1105212016"
, andDelegate:
nil
)
}
@IBAction
func
sendMessage(_ sender:
AnyObject
) { {
//消息分享相关代码
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
|
1
2
3
|
let
txtObj =
QQApiTextObject
(text:
"欢迎访问 hangge.com"
)
let
req =
SendMessageToQQReq
(content: txtObj)
QQApiInterface
.send(req)
|
1
2
3
4
5
6
|
let
filePath =
Bundle
.main.path(forResource:
"logo"
, ofType:
"png"
)
let
imgData =
NSData
(contentsOfFile:filePath!)
let
imgObj =
QQApiImageObject
(data: imgData
as
Data
!, previewImageData: imgData
as
Data
!,
title:
"hangge.com"
, description:
"航歌 - 做最好的开发者知识平台"
)
let
req =
SendMessageToQQReq
(content: imgObj)
QQApiInterface
.send(req)
|
1
2
3
4
5
6
7
8
9
|
let
newsUrl =
URL
(string:
"http://www.hangge.com"
)
let
title =
"新闻标题"
let
description =
"新闻描述"
let
previewImageUrl =
URL
(string:
"http://www.hangge.com/blog/images/logo.png"
)
let
newsObj =
QQApiNewsObject
(url: newsUrl, title: title, description: description,
previewImageURL: previewImageUrl,
targetContentType:
QQApiURLTargetTypeNews
)
let
req =
SendMessageToQQReq
(content: newsObj)
QQApiInterface
.send(req)
|
1
2
3
4
5
6
7
8
9
10
11
12
|
let
url =
URL
(string:
"http://y.qq.com/i/song.html?songid=432451&source=mobileQQ%23wechat_redirect"
)
let
title =
"歌曲名:不要说话"
let
descriotion =
"专辑名:不想放手歌手名:陈奕迅"
let
previewImageUrl =
URL
(string:
"http://imgcache.qq.com/music/photo/mid_album_300/V/E/000J1pJ50cDCVE.jpg"
)
let
audioObj =
QQApiAudioObject
(url: url, title: title, description: descriotion,
previewImageURL: previewImageUrl,
targetContentType:
QQApiURLTargetTypeAudio
)
let
req =
SendMessageToQQReq
(content: audioObj)
QQApiInterface
.send(req)
|
1
2
3
4
5
6
7
|
let
url =
URL
(string:
"http://v.qq.com/cover/5/53x6bbyb07ebl3s/n0013r8esy6.html"
)
let
previewImageUrl =
URL
(string:
"http://www.hangge.com/blog/images/logo.png"
)
let
videoObj =
QQApiVideoObject
(url: url, title:
"黑子的篮球"
, description:
"第一季第一集"
,
previewImageURL: previewImageUrl,
targetContentType:
QQApiURLTargetTypeVideo
)
let
req =
SendMessageToQQReq
(content: videoObj)
QQApiInterface
.send(req)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import
UIKit
class
ViewController
:
UIViewController
{
var
_tencentOAuth:
TencentOAuth
!
override
func
viewDidLoad() {
super
.viewDidLoad()
_tencentOAuth =
TencentOAuth
.
init
(appId:
"1105212016"
, andDelegate:
nil
)
}
//纯文本消息发送
@IBAction
func
sendTextMessage(_ sender:
AnyObject
) {
let
txtObj =
QQApiTextObject
(text:
"欢迎访问 hangge.com"
)
let
req =
SendMessageToQQReq
(content: txtObj)
//发送并获取响应结果
let
sendResult =
QQApiInterface
.send(req)
//处理结果
handleSendResult(sendResult: sendResult)
}
//处理分享返回结果
func
handleSendResult(sendResult:
QQApiSendResultCode
){
var
message =
""
switch
(sendResult){
case
EQQAPIAPPNOTREGISTED
:
message =
"App未注册"
case
EQQAPIMESSAGECONTENTINVALID
,
EQQAPIMESSAGECONTENTNULL
,
EQQAPIMESSAGETYPEINVALID
:
message =
"发送参数错误"
case
EQQAPIQQNOTINSTALLED
:
message =
"QQ未安装"
case
EQQAPIQQNOTSUPPORTAPI
:
message =
"API接口不支持"
case
EQQAPISENDFAILD
:
message =
"发送失败"
case
EQQAPIQZONENOTSUPPORTTEXT
:
message =
"空间分享不支持纯文本分享,请使用图文分享"
case
EQQAPIQZONENOTSUPPORTIMAGE
:
message =
"空间分享不支持纯图片分享,请使用图文分享"
default
:
message =
"发送成功"
}
print
(message)
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
|