Line SDK 接入

Line 是一种类似微信、QQ的社交工具,维基百科介绍如下:

   LINE(日语:ライン,韓語:라인,官方中文名:連我),是一個即時通

信軟體與流動應用程式,於2011年6月發表。用戶間可以通過互聯網在不額外

增加費用情況下與其他用戶傳送文字、圖片、動畫、語音和影片等多媒體信息

(甚至進行語音通話)。在2016年3月以來,LINE於全球擁有超過10億人註冊

使用,其中約有高達2.15億活躍用戶.

公司项目需要接入Line登录和分享功能,分享一下接入时踩的坑, 本文使用的SDK版本为 3.2.1。

首先在国内的AppStore上是搜索不到Line的APP的。需要登录一个国外的AppStore才能下载Line的。 创建国外地区的AppleID , 下载完成之后,可以注册Line的账号了,可以使用国内的手机号码注册。

首次登陆Line的开发者网站(当然需要准备VPN),需要客户端上了App进行授权验证。

创建应用,下载SDK之后,就可以接入了。 然后Xcode工程可以按照官网上设置 iOS SDK 接入登录地址 , 其中设置白名单的时候,如果需要接入分享功能,增加 line 字段,效果如下:

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>lineauth</string>
 <string>line3rdp.$(APP_IDENTIFIER)</string>
 <string>line</string>
</array>

获取用户信息接口如下:

[[mAdapter getLineApiClient] getMyProfileWithResultBlock:^(NSDictionary *aResult, NSError *aError)
{
    if (aResult)
    {
        NSString *displayName = aResult[@"displayName"];
        NSString *mid = aResult[@"id"];
        NSString *pictureUrl = aResult[@"pictureUrl"];
        NSString *statusMessage = aResult[@"statusMessage"];
        // do something...
    }
    else
    {
        NSLog(@"%@", aError);
        // do something for error...
    }
}];

其中在获取的头像的url添加'/large'能获取到200200大小的图片, 添加'/small' 能获取 5151 大小的图片**

line 的分享主要是按照如下方式进行的

line://msg/<CONTENT TYPE>/<CONTENT KEY>

可以分享文字或者图片,分享文字<CONTENT TYPE> 的值为 text , 分享图片<CONTENT TYPE> 的值为 image 。 <CONTENT TYPE> 的值需要进行 UTF-8 编码.

分享文字:

- (BOOL)shareMessage:(NSString *)message
{
    NSString *contentType = @"text";
    NSString *urlString = [NSString stringWithFormat:@"line://msg/%@/%@",contentType, message];
    [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlString];
    
    if ([[UIApplication sharedApplication]canOpenURL:url]) {
        return [[UIApplication sharedApplication]openURL:url];
    }else{
        return NO;
    }
}

分享图片:

- (BOOL)sharePicture:(NSString *)pictureUrl
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
    UIImage *image = [UIImage imageWithData:data];
    [pasteboard setData:UIImageJPEGRepresentation(image, 0.9) forPasteboardType:@"public.jpeg"];
    NSString *contentType =@"image";
    
    NSString *contentKey = [pasteboard.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSString *urlString = [NSString stringWithFormat:@"line://msg/%@/%@",contentType, contentKey];
    NSURL *url = [NSURL URLWithString:urlString];
    
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        return [[UIApplication sharedApplication] openURL:url];
    }else{
        return NO;
    }

}


分享图片时 <CONTENT KEY> 的值,官网说明如下:

Specify value in percent encoded (utf-8) text.
By principle, only the page title and page URL may be specified.
* When sending from iPhone apps, please attach the image to the Pasteboard and set a PasteboardName in the following format: line://msg/image/(PasteboardName)
* When sending from Android devices, please specify a local image path that can be accessed by LINE in the following format: line://msg/image/(localfilepath)
* Specifying information irrelevant to the page is prohibited under the Guidelines.

参考资料

开发者官网地址

iOS SDK 分享接入地址

UTI 介绍

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容