彩票4、0620 (打电话 发短信 发邮件) (app store 评分) (转盘) (block循环引用问题注意 ) (autoResizing)

-------------

打电话  发短信  发邮件

直接拷贝代码即可

 MFMessage

//  NJShareViewController.m
//  09-彩票(lottery)

#import "NJShareViewController.h"
#import <MessageUI/MessageUI.h>


@interface NJShareViewController ()<MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate>

@end

@implementation NJShareViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"分享设置";
    
    // 1.1.新浪微博
    NJSettingArrowItem *weibo = [[NJSettingArrowItem alloc] initWithIcon:@"WeiboSina" title:@"新浪微博"];
    
    // 1.2.短信分享
    NJSettingArrowItem *sms = [[NJSettingArrowItem  alloc ]initWithIcon:@"SmsShare" title:@"短信分享"];
    sms.option = ^{
        // 如果利用该方式发送短信, 当短信发送完毕或者取消之后不会返回应用程序
//        NSURL *url = [NSURL URLWithString:@"sms://10010"];
//        [[UIApplication sharedApplication] openURL:url];
        
        // 判断当前设备能否发送短信
        if (![MFMessageComposeViewController canSendText]) {
            NSLog(@"当前设备不能发送短信");
            return ;
        }
        
        MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
        // 设置短信内容
        vc.body = @"吃饭了没?";
        // 设置收件人列表
        vc.recipients = @[@"10010"];
        // 设置代理
        vc.messageComposeDelegate = self;
        // 显示控制器
        [self presentViewController:vc animated:YES completion:nil];

    };
    
    // 1.3.邮件分享
    NJSettingArrowItem *mail = [[NJSettingArrowItem alloc] initWithIcon:@"MailShare" title:@"邮件分享"];
    mail.option = ^{
        // 当邮件发送成功或者失败或者取消之后不会回到原来的应用程序
//        NSURL *url = [NSURL URLWithString:@"mailto://10010@qq.com"];
//        [[UIApplication sharedApplication] openURL:url];

        
        // 不能发邮件
        if (![MFMailComposeViewController canSendMail]) return;
        
        // 当邮件发送成功或者失败或者取消之后会回到原始程序
        MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
        
        // 设置邮件主题
        [vc setSubject:@"会议"];
        // 设置邮件内容
        [vc setMessageBody:@"今天下午开会吧" isHTML:NO];
        // 设置收件人列表
        [vc setToRecipients:@[@"643055866@qq.com"]];
        // 设置抄送人列表
        [vc setCcRecipients:@[@"1234@qq.com"]];
        // 设置密送人列表
        [vc setBccRecipients:@[@"56789@qq.com"]];
        
        // 添加附件(一张图片)
        UIImage *image = [UIImage imageNamed:@"lufy.jpeg"];
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        [vc addAttachmentData:data mimeType:@"image/jepg" fileName:@"lufy.jpeg"];
        
        // 设置代理
        vc.mailComposeDelegate = self;
        // 显示控制器
        [self presentViewController:vc animated:YES completion:nil];

        
    };
    
    NJSettingGroup *group = [[NJSettingGroup alloc]init];
    group.items = @[weibo, sms, mail];
    
    [self.datas addObject:group];
}

#pragma mark - MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    // 关闭邮件界面
    [controller dismissViewControllerAnimated:YES completion:nil];
    
    if (result == MFMailComposeResultCancelled) {
        NSLog(@"取消发送");
    } else if (result == MFMailComposeResultSent) {
        NSLog(@"已经发出");
    } else {
        NSLog(@"发送失败");
    }
}


#pragma mark - MFMessageComposeViewController
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    NSLog(@"didFinishWithResult");
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
    if (MessageComposeResultCancelled == result) {
        NSLog(@"取消发送");
    }else if (MessageComposeResultSent == result)
    {
        NSLog(@"发送成功");
    }else
    {
        NSLog(@"发送失败");
    }
}

@end

 

 

发短信和发邮件

----------------

app store 评分

评分url路径格式   itms-apps://itunes.apple.com/cn/app/id这里填appId数值?mt=8    

这个appid是在发布应用程序的时候可以看到一个生成的界面

-----------------------

打开其他应用(如:切水果等)
每个应用程序都有一个自定义的url地址

自定义协议为       lnj://ios.itcast.cn

 

 ---------------------------------

转盘

 

---

 

 

 ---------------------------------------

block循环引用问题注意

block循环引用问题解决
@property (nonatomic,copy) BlockAbc option;
obj.option  =  ^{
    这里面不能出现self   obj   或者强引用obj的对象   如果要使用self 应该用一个若指针变量a指向self 然后在用a来完成操作
}

示例:

官方推荐控件使用weak  因为self.view addSubview数组已经强引用sw了

----------

autoResizing

 

posted @ 2016-03-14 11:24  海龙王来了  阅读(147)  评论(0)    收藏  举报
友情链接:废钢破碎机  带式压滤机