欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS錄屏和截屏監(jiān)聽的實(shí)現(xiàn)代碼

 更新時(shí)間:2018年05月10日 13:46:53   作者:關(guān)注見慣就不怪  
本篇文章主要介紹了iOS錄屏和截屏監(jiān)聽的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

最近在做項(xiàng)目安全性方面的工作,需要在APP內(nèi)敏感頁面做防用戶截屏錄屏的功能,就在網(wǎng)上查閱了一些資料,在這里做個(gè)筆記,方便日后查找。

截屏狀態(tài)獲取

編輯相冊中最新照片的方法iOS8之后就已經(jīng)失效,框架“Photos”也在iOS10之后失效。

搜索發(fā)現(xiàn)UIApplication中僅有用戶截屏后的通知,應(yīng)用中只會收到已經(jīng)截屏的通知并沒辦法干預(yù)。

// This notification is posted after the user takes a screenshot (for example by pressing both the home and lock screen buttons)
UIKIT_EXTERN NSNotificationName const UIApplicationUserDidTakeScreenshotNotification NS_AVAILABLE_IOS(7_0);

雖然無法直接干預(yù),但可以知道用戶截屏了就可以用其它的方式來限制用戶的行為或者彈出提示告訴用戶。

-(void)viewDidAppear:(BOOL)animated{
  [super viewDidAppear:animated];
  
  [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

-(void)screenshots
{
  UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:nil message:@"[安全提醒]內(nèi)含個(gè)人資金賬戶。不要截圖,錄制或分享給他人以保障資金賬戶安全。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"確定", nil];
  [alert1 show];

-(void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

錄屏狀態(tài)獲取

iOS 11 SDK 中新增了UIScreen的API用以告知應(yīng)用當(dāng)前屏幕正在錄屏。當(dāng)UIScreen.isCaptured 為true時(shí),表示當(dāng)前屏幕正在被錄制、鏡像或被Airplay 發(fā)送。

當(dāng)錄屏狀態(tài)發(fā)生變化時(shí),UIKit會發(fā)送UIScreenCapturedDidChange的notification。

基于此,我們可以在應(yīng)用中接收此通知,來對用戶的錄屏行為做相應(yīng)的處理

-(void)viewWillAppear:(BOOL)animated{
  [super viewWillAppear:animated];

//監(jiān)測當(dāng)前設(shè)備是否處于錄屏狀態(tài)
  UIScreen * sc = [UIScreen mainScreen];
  if (@available(iOS 11.0, *)) {
    if (sc.isCaptured) {
      NSLog(@"正在錄制~~~~~~~~~%d",sc.isCaptured);
      [self screenshots];
    }
  } else {
    // Fallback on earlier versions
  }
  if (@available(iOS 11.0, *)) {
//檢測到當(dāng)前設(shè)備錄屏狀態(tài)發(fā)生變化
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIScreenCapturedDidChangeNotification object:nil];
  } else {
    // Fallback on earlier versions
  }
}

-(void) screenshots
{
  UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:nil message:@"[安全提醒]內(nèi)含個(gè)人資金賬戶。不要截圖,錄制或分享給他人以保障資金賬戶安全。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"確定", nil];
  [alert1 show];

-(void)dealloc
{
  if (@available(iOS 11.0, *)) {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenCapturedDidChangeNotification object:nil];
  } else {
    // Fallback on earlier versions
  }
}

上述監(jiān)測錄屏狀態(tài)只是在iOS11之后,而且只是單單的檢測到錄屏狀態(tài)并且沒有辦法去關(guān)閉錄屏狀態(tài)或者修改錄制到的內(nèi)容,至于在iOS11之前的錄屏手段的監(jiān)測暫時(shí)還沒查到,有哪位大神知道的話麻煩告知小弟,在此謝過。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論