大杂烩


/*
 *创建短信视图
 *引入#import <MessageUI/MessageUI.h>
          #import <MessageUI/MFMessageComposeViewController.h>

          服从 : MFMessageComposeViewControllerDelegate

           导入messageUI.frameworks


 */
-(void)createMessageViewControllerWithPhoneNum:(NSString *)phoneNum
{
    MFMessageComposeViewController *picker =
    [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;
    picker.navigationBar.tintColor = [UIColor blackColor];
    // 默认收件人(可多个)
    picker.recipients = [NSArray arrayWithObject:phoneNum];
    [self addSMSEventWithPhoneNum:phoneNum];
    
    if (picker) {
        
        [self presentViewController:picker
                           animated:YES
                         completion:^{
                             
                         }];
    }else{
        
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",phoneNum]]];
    }
}

#pragma mark - MFMessageComposeViewControllerDelegate

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MessageComposeResultCancelled:
            
            break;
        case MessageComposeResultSent:
            showMsg(@"发送成功");
            break;
        case MessageComposeResultFailed:
            
            break;
        default:
            break;
    }
    
    [controller dismissViewControllerAnimated:YES completion:^{
        
    }];
}



//打电话
- (BOOL)callPhone:(NSString *)num {
    
    if (![CommonMethod isPhoneSupported]) {
        showMsg(@"当前设备不支持拨打电话");
        return NO;
    }
    
    NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", num]];
    [[UIApplication sharedApplication] openURL:telURL];
    
    BaiduMobStat *statCallEvent = [BaiduMobStat defaultStat];
    [statCallEvent logEvent:@"call" eventLabel:num];
    
    return YES;
}

//添加发短信事件
-(void)addSMSEventWithPhoneNum:(NSString *)phoneNum
{
    
    BaiduMobStat *statCallEvent = [BaiduMobStat defaultStat];
    [statCallEvent logEvent:@"sms" eventLabel:phoneNum];
}


//设备是否支持打电话
+ (BOOL)isPhoneSupported {
    NSString* deviceType = [UIDevice currentDevice].model;
    return [deviceType isEqualToString:@"iPhone"];
}




  //添加百度统计
    BaiduMobStat *statTracker = [BaiduMobStat defaultStat];
    statTracker.enableExceptionLog = YES;
    statTracker.logSendWifiOnly = YES;
    //当前版本号
    NSString * appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    statTracker.shortAppVersion = appVersion;
    statTracker.channelId = @"appstore";
    statTracker.enableDebugOn = YES;
    statTracker.sessionResumeInterval = 30;
    [statTracker startWithAppId:BaiduMobStatAppKey];






-(void)initHUDView
{
    mbHUD = [[MBProgressHUD alloc]initWithView:self.view];
    mbHUD.mode = MBProgressHUDModeIndeterminate;
    [self.view addSubview:mbHUD];
}

-(void)showLoadingView:(NSString *)message
{
    if (mbHUD) {
        
        mbHUD.labelText = message ? message : @"加载中...";
        [mbHUD show:YES];
    }
}

-(void)hiddenLoadingView
{
    if (mbHUD) {
        [mbHUD hide:YES];
    }
}

#pragma mark - MBProgressHUD
-(void)initOnlyTextHUDView
{
    onlyTextHUD = [[MBProgressHUD alloc]initWithView:self.view];
    onlyTextHUD.mode = MBProgressHUDModeText;
    [self.view addSubview:onlyTextHUD];
}

-(void)showOnlyTextAlertView:(NSString *)message
{
    if (onlyTextHUD) {
        
        onlyTextHUD.labelText = message ? message : @"操作成功";
        [onlyTextHUD show:YES];
        
        [self performSelector:@selector(hiddenOnlyTextAlertView)
                   withObject:nil
                   afterDelay:1.0];
    }
}

-(void)hiddenOnlyTextAlertView
{
    if (onlyTextHUD) {
        [onlyTextHUD hide:YES];
    }
}


- (void)clearCache
{
    [self showLoadingView:@"清除缓存中..."];
    
    [SDWebImageManager.sharedManager.imageCache clearMemory];
    [SDWebImageManager.sharedManager.imageCache clearDisk];
    
    [[SDImageCache sharedImageCache] calculateSizeWithCompletionBlock:^(NSUInteger fileCount, unsigned long long totalSize) {
       
        [self hiddenLoadingView];
        
        [_mainTableView reloadData];
    }];
    

}

if (indexPath.row == 2)
    {
        
        NSString* cacheSize = [NSString stringWithFormat:@"%@",@([[SDImageCache sharedImageCache] getSize])];
        
        if (![cacheSize isEqualToString:@"0"])
        {
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%.1f M",cacheSize.floatValue/1024.0/1024.0] ;
        }
        else
        {
            cell.detailTextLabel.text = @"0 KB";
        }
    }






//加边虚线


    CAShapeLayer *border = [CAShapeLayer layer];
    border.strokeColor = [UIColor redColor].CGColor;
    border.fillColor = nil;
    border.path = [UIBezierPath bezierPathWithRect:self.button.bounds].CGPath;
    border.frame = self.button.bounds;
    border.lineWidth = 1.f;
    border.lineCap = @"square";
    border.lineDashPattern = @[@6, @6];
    [self.button.layer addSublayer:border];


/*
 *设置行间距
 *
 */
+(NSMutableAttributedString *)setLabelParagraphStyleWithString:(NSString *)changeStr andLineSpacing:(CGFloat)lineSpacing
{
    NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:changeStr];
    
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpacing];
    [attributedString addAttribute:NSParagraphStyleAttributeName
                             value:paragraphStyle
                             range:NSMakeRange(0, [changeStr length])];
    return attributedString;
}




先介绍一种最简单的方法:

调用打电话功能

[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];

调用发短信功能

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10000"]];


上面的发短信的功能是调用系统的界面,下面是实现一种点击按键就直接发送短信,相当于后台发送,能不能上软件商店,还不能确定。相对建议来说,尽量使用第一种。

首先导入MFMessageComposeViewControllerDelegate这个代理,实现里面的方法

-(void)messageComposeViewController:(MFMessageComposeViewController *)controllerdidFinishWithResult:(MessageComposeResult)result {

     

      //Notifies users about errors associated with the interface

      switch (result) {

         case MessageComposeResultCancelled:

            if (DEBUG)NSLog(@"Result: canceled");

            break;

         case MessageComposeResultSent:

            if (DEBUG)NSLog(@"Result: Sent");

            break;

         case MessageComposeResultFailed:

            if (DEBUG)NSLog(@"Result: Failed");

            break;

         default:

            break;

      }

      [self dismissModalViewControllerAnimated:YES]; 

}

群发短信:

- (IBAction)sendSMS {

     

      BOOL canSendSMS = [MFMessageComposeViewControllercanSendText];

      NSLog(@"can send SMS [%d]",canSendSMS); 

      if (canSendSMS) {

     

         MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc]init];

         picker.messageComposeDelegate =self;

         picker.navigationBar.tintColor = [UIColorblackColor];

         picker.body = @"test";

         picker.recipients = [NSArrayarrayWithObject:@"10086"];

         [self presentModalViewController:picker animated:YES];

         [picker release];   

      } 

}

给一个人发短信:

从网页上获得内容

-(void)displaySMSComposerSheet

{

    MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc]init];

    picker.messageComposeDelegate =self;

    UIWebView *web = nil;

    NSMutableString* absUrl = [[NSMutableStringalloc]initWithString:web.request.URL.absoluteString];

    [absUrl replaceOccurrencesOfString:@"http://i.aizheke.com"withString:@"http://m.aizheke.com"options:NSCaseInsensitiveSearchrange:NSMakeRange(0, [absUrllength])];

    picker.body=[NSStringstringWithFormat:@"我在爱折客上看到:%@可能对你有用,推荐给你!link%@",[webstringByEvaluatingJavaScriptFromString:@"document.title"],absUrl];

   [absUrl release];

   [self presentModalViewController:picker animated:YES];

   [picker release];

}

事件绑定发送短信

-(IBAction)showSMSPicker:(id)sender {

    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

    if (messageClass != nil) {

        if ([messageClass canSendText]) {

            [self displaySMSComposerSheet];

        }

        else {

//设备没有短信功能

       }

    }

    else {

// iOS版本过低,iOS4.0以上才支持程序内发送短信

    }

}

以上内容有一部分是来各个网站,本人自己加上自己的理解,整理,至于来源于互联网的那一部分作者是谁,来自于哪里,我现在也不知道了,写出来供大家学习。如果有你是那一部分的作者,请联系我!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值