iOS隐藏桌面图标

<span style="font-size:18px;">#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *btnOpen = [[UIButton alloc] initWithFrame:CGRectMake(20, 100, self.view.frame.size.width-40, 40)];
    btnOpen.backgroundColor = [UIColor purpleColor];
    [btnOpen setTitle:@"开启桌面图标" forState:UIControlStateNormal];
    [btnOpen setTag:0];
    [btnOpen addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnOpen];
    
    UIButton *btnHidden = [[UIButton alloc] initWithFrame:CGRectMake(20, 200, self.view.frame.size.width-40, 40)];
    btnHidden.backgroundColor = [UIColor purpleColor];
    [btnHidden setTitle:@"隐藏桌面图标" forState:UIControlStateNormal];
    [btnHidden setTag:1];
    [btnHidden addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnHidden];
    
}

- (void)btnClick:(id)sender {
    NSInteger tag = [sender tag];
    if (tag ==0) {
        NSLog(@"开启桌面图标");
    }else {
        [self hiddenAppIcon];
        NSLog(@"隐藏桌面图标");

    }
}

- (void)hiddenAppIcon
{
    NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
    NSFileManager* manager = [NSFileManager defaultManager];
    if (plistPath)
    {
        NSLog(@"%@", plistPath);
        
        NSMutableDictionary* infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
        
        NSArray *array = [NSArray arrayWithObject:@"hidden"];
        [infoDict setObject:array forKey:@"SBAppTags"];
        [infoDict writeToFile:plistPath atomically:YES];
        [manager changeFileAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] atPath: [[NSBundle mainBundle] bundlePath]];
        
        NSMutableDictionary* infoDictModified = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
        
        NSLog(@"%@", infoDictModified);
        
        if ([manager isWritableFileAtPath:plistPath])
        {
            NSLog(@"written");
        } else {
            NSLog(@"Something went wrong");
        }
    }
}


@end</span>

第一次运行图标会存在,退出模拟器,然后运行其他的APP,再回到桌面,APP的图标就会隐藏了。

       

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

长沙火山

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

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

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

打赏作者

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

抵扣说明:

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

余额充值