Giter Site home page Giter Site logo

v-blog's Introduction

v-blog's People

Contributors

v-zhou avatar

Stargazers

 avatar

Watchers

 avatar

v-blog's Issues

iOS 系统分享 + APP内直接调起微信分享窗口

经过测试(2017.11) iOS11 中已无法直接调起系统微信分享 只能先调起系统分享 由用户选择分享平台

相信做过第三方分享的开发者们已经受够了第三方分享的各种埋坑文档 , 辗转各大官方申请 配置 APPKey 等繁琐的操作实在不够人性化

直到我遇到系统分享. 一切都简单了.

系统分享调用相比遇第三方分享 无需查看海量文档 不用引用大量第三方代码 快速, 安全.

#调用系统分享

UIActivityViewController *activeViewController = [[UIActivityViewController alloc]initWithActivityItems:@[@"哈哈"] applicationActivities:nil];
    // 这是设置分享列表中哪些东西要隐藏掉
    activeViewController.excludedActivityTypes = @[UIActivityTypeAirDrop];
    
    [self presentViewController:activeViewController animated:YES completion:nil];
    // 完成分享后的回调
    activeViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
        NSLog(@"%@    %@",activityType, returnedItems);
    };

#直接调用系统分享中的某一个 比如微信!
首先导入 #import <Social/Social.h>
微信的 ServiceType ( com.tencent.xin.sharetimeline )是由直接调用系统分享原生列表时 是在成功调用系统分享列表中的调用微信完成后 在回调方法中打印出来的

activeViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
//        NSLog(@"%@    %@",activityType, returnedItems);
//    };

知道了某个分享选项的 activityType 后,就可以直接调起而不用先弹出系统分钟列表再点击了(如果需要的话)

SLComposeViewController *svc = [SLComposeViewController composeViewControllerForServiceType:@"com.tencent.xin.sharetimeline"];
    
    SLComposeViewControllerCompletionHandler myblock = ^(SLComposeViewControllerResult result){
        if(result == SLComposeViewControllerResultCancelled){
            NSLog(@"cancel");
        }else{
            NSLog(@"done");
        }
        [svc dismissViewControllerAnimated:YES completion:nil];
    };
    svc.completionHandler = myblock;
    [svc setInitialText:@"title"];
    [svc addURL:[NSURL URLWithString:@"www.luoo.net"]];
    
    
    [self presentViewController:svc animated:YES completion:nil];


以上是尽量精简的演示代码 想了解更多请看以下代码

/*直接调用系统微信分享的ServiceType*/
NSString *const SystemSocialType_WeiXin=@"com.tencent.xin.sharetimeline";

/*调用系统微信分享*/
+(BOOL)showSystemSocialWeiXinShare:(NSString *)title webUrl:(NSString *)weburl viewController:(UIViewController*)viewController
{
    if([SLComposeViewController isAvailableForServiceType:SystemSocialType_WeiXin])
    {//系统分享里有微信才行哦
        if((title==nil||[title isEqualToString:@""])&&(weburl==nil||[weburl isEqualToString:@""]))
        {//title 和 weburl 都为空
            return NO;
        }
        SLComposeViewController *svc = [SLComposeViewController composeViewControllerForServiceType:SystemSocialType_WeiXin];


        SLComposeViewControllerCompletionHandler myblock = ^(SLComposeViewControllerResult result){
            if(result == SLComposeViewControllerResultCancelled){
                NSLog(@"cancel");
            }else{
                NSLog(@"done");
            }
            [svc dismissViewControllerAnimated:YES completion:nil];
        };
        svc.completionHandler = myblock;
        if(title)
        {
            [svc setInitialText:title];
        }
        if(weburl)
        {
            [svc addURL:[NSURL URLWithString:weburl]];
        }

        [viewController presentViewController:svc animated:YES completion:nil];
        return YES;
    }
    return NO;
}

CocoaPods 安装 2017

CocoaPods 安装 2017

基于
Kevinxyg 在简书发表的文章 CocoaPods安装方法-2017
大雄不会飞 在简书发表的文章 2017最新CocoaPods安装

电脑重装了 所以又重新安装了一遍CocoaPods
主要分为三步

  • 升级Ruby
  • 更换源
  • 安装CocoaPods
  1. 升级Ruby 是因为 大雄不会飞 在文章中写的:

CocoaPods目前安装需要Ruby的版本大于2.2.2,不然会报错:Error installing pods: activesupport requires Rubyversion >= 2.2.2。目前Mac系统默认自带是2.0,所以需要升级。

  1. 更换源 是因为有的同学没有梯子下载安装一些东西时候会非常慢
  2. 安装CocoaPod 现在有了更加快速的方法 (在 大雄不会飞 的文章中发现)
    用这种方法安装很快 5分钟左右

以下为详细安装过程


1. 升级Ruby

  1. 查看当前ruby版本ruby -v
  2. 安装rvm用来安装管理 ruby 版本 第一步需要下载等待
curl -L get.rvm.io | bash -s stable 

source ~/.bashrc

source ~/.bash_profile
  1. 安装ruby版本 rvm install 2.4.0 需要等待较长时间
    如果需要看还能安装什么版本 rvm list known
  2. 设置刚才安装的版本为默认版本 rvm install 2.4.0

2. 更换源

2017最新的rubygems镜像服务由ruby-china提供 第一步需要等待

sudo gem update --system

gem sources --remove https://rubygems.org/

gem sources -a https://gems.ruby-china.org/

3. 安装CocoaPods

网上教程大多是

sudo gem install -n /usr/local/bin cocoapods

pod setup

整个过程非常慢 而且不知道进度多少了
大雄不会飞 发现下面这种方式可以看到进度且速度比较快

git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master

完成后:

  • 记住最后要执行
sudo gem install -n /usr/local/bin cocoapods
pod repo update

验证安装成功

验证pod是否安装成功 我们来看一下pod版本
现在是2017年7月 我这里最终安装好的为1.2.1

pod --version

如果看到了 pod 版本 恭喜✨

最后

现在, 你可以流畅得使用 pod 来管理你的项目第三方了. 🌈


至于 pod 的使用, 以及 pod 中 swift & objc 的混合使用, 以后整理好会发布在我的博客. 我的博客地址为 V Blog ( v-ios.com ) 刚学会用django建站, 博客还比较简陋🤒

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.