剪切板的使用

获取全局的剪切板内容并作出提示


在这个方法中去拦截剪贴版的内容并做判读

- (void)applicationDidBecomeActive:(UIApplication *)application 

对获取到内容的处理

  UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  if ([pasteBoard.string hasPrefix:@"http://"] ||
      [pasteBoard.string hasPrefix:@"https://"]) {
    UIAlertController *alertVc = [UIAlertController
        alertControllerWithTitle:@"要打开其中的链接吗?"
                         message:nil
                  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionConfirm =
        [UIAlertAction actionWithTitle:@"打开"
                                 style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction *_Nonnull action) {
                                 NSLog(@"打开链接");//打开链接要做的跳转操作
                               }];
    UIAlertAction *actionRefuse =
        [UIAlertAction actionWithTitle:@"忽略"
                                 style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction *_Nonnull action) {
                                 NSLog(@"忽略");// 忽略的跳转操作
                                  pasteboard.string = @"";
                               }];
    [alertVc addAction:actionConfirm];
    [alertVc addAction:actionRefuse];
    [self.window.rootViewController presentViewController:alertVc
                                                 animated:YES
                                               completion:nil];
  }

这个哥们的swift版本的,我就手写试试OC的,大概也是这个意思吧

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容