當應用進入後台時,系統會自動在當前應用的頁面截圖並儲存到手機內,如果當前頁面涉及敏感資訊時,被攻擊會造成洩密。如下圖生成的兩張路徑:
防止造成資訊洩露 - 新增高斯模糊(參考支付寶掛起時的模糊效果)
實現方案:
- (blurview *)backgroundbar{
if (!_backgroundbar) {
_backgroundbar = [[blurview alloc] initwithframe:[uiscreen mainscreen].bounds];
return _backgroundbar;
__weak typeof(self)weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
if (window.windowlevel == uiwindowlevelnormal) {
[window addsubview:weakself.backgroundbar];
__weak typeof(self)weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakself.backgroundbar removefromsuperview];
weakself.backgroundbar = nil;
模糊檢視實現方案
#import "cmfkblurview.h"
#import
#define screenwidth screen_width
#define screenheight screen_height
#define screenscale ([uiscreen mainscreen].scale)
#if __iphone_os_version_max_allowed > __iphone_6_1
#define kcgimagealphapremultipliedlast (kcgbitmapbyteorderdefault | kcgimagealphapremultipliedlast)
#else
#define kcgimagealphapremultipliedlast kcgimagealphapremultipliedlast
#endif
@implementation cmfkblurview
- (instancetype)initwithframe:(cgrect)frame{
self = [super initwithframe:frame];
if (self) {
uiimage *image = [uiimage imagewithdata:uiimagejpegrepresentation([self getcurrentimage], 1.0)];
self.blurimage = [self blurryimage:image withblurlevel:0.3];
uiimageview *bgview = [[uiimageview alloc] initwithframe:frame];
bgview.image =self.blurimage;
[self addsubview:bgview];
return self;
- (uiimage *)getcurrentimage{
uigraphicsbeginimagecontextwithoptions(cgsizemake(screenwidth*screenscale,screenheight*screenscale),yes, 0);//截圖
uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();
uigraphicsendimagecontext();
cgimageref imageref = viewimage.cgimage;
cgrect rect =cgrectmake(0,0, screenwidth*screenscale,screenheight*screenscale);
cgimageref imagerefrect =cgimagecreatewithimageinrect(imageref, rect);
uiimage *sendimage = [[uiimage alloc] initwithcgimage:imagerefrect];
cgimagerelease(imagerefrect);
return sendimage;
//模糊演算法
- (uiimage *)blurryimage:(uiimage *)image withblurlevel:(cgfloat)blur {
if (blur <0.f || blur > 1.f) {
blur = 0.5f;
int boxsize = (int)(blur *100);
boxsize = boxsize - (boxsize % 2) +1;
cgimageref img = image.cgimage;
vimage_buffer inbuffer, outbuffer;
vimage_error error;
void *pixelbuffer;
cgdataproviderref inprovider =cgimagegetdataprovider(img);
cfdataref inbitmapdata =cgdataprovidercopydata(inprovider);
inbuffer.width =cgimagegetwidth(img);
inbuffer.height =cgimagegetheight(img);
inbuffer.rowbytes =cgimagegetbytesperrow(img);
inbuffer.data = (void*)cfdatagetbyteptr(inbitmapdata);
pixelbuffer = malloc(cgimagegetbytesperrow(img) *cgimagegetheight(img));
if(pixelbuffer ==null)
nslog(@"no pixelbuffer");
outbuffer.data = pixelbuffer;
outbuffer.width =cgimagegetwidth(img);
outbuffer.height =cgimagegetheight(img);
outbuffer.rowbytes =cgimagegetbytesperrow(img);
error = vimageboxconvolve_argb8888(&inbuffer, &outbuffer, null, 0, 0, boxsize, boxsize, null, kvimageedgeextend);
if (error) {
nslog(@"error from convolution %ld", error);
cgcolorspaceref colorspace =cgcolorspacecreatedevicergb();
cgcontextref ctx =cgbitmapcontextcreate(outbuffer.data,outbuffer.width,outbuffer.height,8,outbuffer.rowbytes,colorspace,kcgimagealphapremultipliedlast);
cgimageref imageref =cgbitmapcontextcreateimage (ctx);
uiimage *returnimage = [uiimage imagewithcgimage:imageref];
//clean up
cgcontextrelease(ctx);
cgcolorspacerelease(colorspace);
free(pixelbuffer);
cfrelease(inbitmapdata);
cgcolorspacerelease(colorspace);
cgimagerelease(imageref);
return returnimage;
參考文章:
nohup後台掛起
nohup nohup 命令執行由 command引數和任何相關的 arg引數指定的命令,忽略所有結束通話 sighup 訊號。在登出後使用 nohup 命令執行後台中的程式。要執行後台中的 nohup 命令,新增 表示 and 的符號 到命令的尾部。nohup 是 no hang up 的縮寫,就...
linux後台執行 掛起 恢復程序相關命令
如果只是臨時有乙個命令需要長時間執行,需要最簡便的保證它在後台穩定執行 我們知道,當使用者登出 logout 或者網路斷開時,終端會收到 hup hangup 訊號從而關閉其所有子程序。因此,我們的解決辦法就有兩種途徑 要麼讓程序忽略 hup 訊號,要麼讓程序執行在新的會話裡從而成為不屬於此終端的子...
iOS 後台定位
和定位可以在後台一直執行著,前提是使用者同意 直接上 viewcontroller.m dingweitest created by user on 15 9 7.import import viewcontroller.h inte ce viewcontroller end implementa...