ios object-c 弹框功能

ios object-c 弹框功能

1、BaseViewController中

	BaseViewController.h
@interface BaseViewController : UIViewController

@end

@interface BaseViewController (Alert)
/**
 系统弹窗双选项
 
 @param title 标题
 @param message 文本内容
 @param ok 确定
 @param cancle 取消
 @param OK 确定按钮回调
 */
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK;

/**
 系统弹窗单选项
 
 @param title 标题
 @param message 具体信息
 @param handler 回调
 */
- (void)alertTitle:(NSString*)title andMessage:(NSString*)message andCancleBlock:(void (^ __nullable)(UIAlertAction *action))handler;

/**
 系统弹窗双选回调
 
 @param title 标题
 @param message 内容
 @param ok ok
 @param cancle cancle
 @param OK ok回调
 @param cancleBlock 取消回调
 */
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK andCancleBlock:(void (^)(UIAlertAction *action))cancleBlock;

@end

BaseViewController.m

@interface BaseViewController ()

@end
@implementation BaseViewController

@end

@implementation BaseViewController (Alert)

- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andCancleBlock:(void (^ __nullable)(UIAlertAction *action))handler
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:handler];
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:ok style:UIAlertActionStyleDestructive handler:OK];
    [alertController addAction:okAction];
    
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancle style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:cancleAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK andCancleBlock:(void (^)(UIAlertAction *action))cancleBlock
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:ok style:UIAlertActionStyleDestructive handler:OK];
    [alertController addAction:okAction];
    
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancle style:UIAlertActionStyleDefault handler:cancleBlock];
    [alertController addAction:cancleAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

@end

2、使用弹框

#import "BaseViewController.h"

@interface MineController : BaseViewController

@end
#import "MineController.h"
@interface MineController ()

@end

@implementation MineController
- (IBAction)deleteButton:(id)sender {
    @weakify(self);
    [self alertTitle:@"确定删除" andMessage:@"" andOK:@"确定" andCancle:@"取消" andBlock:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
                      
    }];
}
@end
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
iOS中使用公钥字符串进行RSA加密的步骤如下: 1. 将公钥字符串转换为NSData类型。 ``` NSString *publicKeyString = @"-----BEGIN PUBLIC KEY-----\n...公钥字符串...\n-----END PUBLIC KEY-----"; NSData *publicKeyData = [publicKeyString dataUsingEncoding:NSUTF8StringEncoding]; ``` 2. 创建SecKey对象。 ``` NSMutableDictionary *publicKeyAttributes = [[NSMutableDictionary alloc] init]; [publicKeyAttributes setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [publicKeyAttributes setObject:@(2048) forKey:(__bridge id)kSecAttrKeySizeInBits]; [publicKeyAttributes setObject:publicKeyData forKey:(__bridge id)kSecValueData]; [publicKeyAttributes setObject:(__bridge id)kSecAttrKeyClassPublic forKey:(__bridge id)kSecAttrKeyClass]; SecKeyRef publicKey; OSStatus status = SecItemAdd((__bridge CFDictionaryRef)publicKeyAttributes, (CFTypeRef *)&publicKey); ``` 3. 使用SecKey对象进行加密。 ``` NSData *plainData = [@"要加密的数据" dataUsingEncoding:NSUTF8StringEncoding]; size_t cipherBufferSize = SecKeyGetBlockSize(publicKey); uint8_t *cipherBuffer = malloc(cipherBufferSize); memset(cipherBuffer, 0, cipherBufferSize); OSStatus status = SecKeyEncrypt(publicKey, kSecPaddingPKCS1, [plainData bytes], [plainData length], cipherBuffer, &cipherBufferSize); NSData *encryptedData = [NSData dataWithBytesNoCopy:cipherBuffer length:cipherBufferSize]; ``` 4. 释放SecKey对象。 ``` CFRelease(publicKey); ``` 注意:在iOS中使用公钥加密时,需要使用PKCS#1填充模式(kSecPaddingPKCS1)。另外,如果公钥字符串中的换行符不是`\n`,需要将其替换为`\n`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玉笛0114

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值