远程获取iOS设备的屏幕截图

远程获取iOS设备的屏幕截图,第1张

概述远程获取iOS设备的屏幕截图

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

#import <QuartzCore/QuartzCore.h>#import <sys/socket.h>#import <netinet/in.h>#import <arpa/inet.h>#import <pthread.h>CFSocketRef _socket;voID* serverThread(voID* context);int setupSocket(voID);voID acceptCallBack(CFSocketRef socket,CFSocketCallBackType type,CFDataRef address,const voID *data,voID *info);voID sendScreenShots(CFWriteStreamRef oStream);voID sendScreenShots(CFWriteStreamRef oStream) {    CGSize screenSize = [[UIScreen mainScreen] bounds].size;    UIGraphicsBeginImageContextWithOptions(screenSize,YES,0);    CGContextRef context = UIGraphicsGetCurrentContext();    UIWindow * window = [[UIApplication sharedApplication] keyWindow];    CGContextSaveGState(context);    CGContextTranslateCTM(context,[window center].x,[window center].y);    CGContextConcatCTM(context,[window transform]);    CGContextTranslateCTM(context,-[window bounds].size.wIDth*[[window layer] anchorPoint].x,-[window bounds].size.height*[[window layer] anchorPoint].y);    [[window layer] renderInContext:context];    CGContextRestoreGState(context);        UIImage *image = UIGraphicsGetimageFromCurrentimageContext();        NSData* imageData = UIImagePNGRepresentation(image);        NSUInteger offset = 0;    NSUInteger buff_size = 1024;    while(imageData.length>offset){        NSUInteger buff_len = imageData.length - offset > buff_size ? buff_size : imageData.length - offset;        CFWriteStreamWrite(oStream,imageData.bytes+offset,buff_len);        offset = offset + buff_len;    }        UIGraphicsEndImageContext();}voID acceptCallBack(CFSocketRef socket,voID *info) {    if (kcfSocketAcceptCallBack == type) {        CFSocketNativeHandle nativeSocketHandle = *(CFSocketNativeHandle *)data;        uint8_t name[SOCK_MAXADDRLEN];        socklen_t nameLen = sizeof(name);        if (0 != getpeername(nativeSocketHandle,(struct sockaddr *)name,&nameLen)) {            close(nativeSocketHandle);        }                //NSLog(@"%s connected.",inet_ntoa( ((struct sockaddr_in *)name)->sin_addr ));        CFWriteStreamRef oStream;        CFStreamCreatePairWithSocket(kcfAllocatorDefault,nativeSocketHandle,NulL,&oStream);        if (oStream) {            CFWriteStreamOpen(oStream);            sendScreenShots(oStream);            CFWriteStreamClose(oStream);            close(nativeSocketHandle);                    } else {            close(nativeSocketHandle);        }    }}int setupSocket() {    _socket = CFSocketCreate(kcfAllocatorDefault,PF_INET,SOCK_STREAM,IPPROTO_TCP,kcfSocketAcceptCallBack,acceptCallBack,NulL);    if (NulL == _socket) {        return 0;    }        int optVal = 1;    setsockopt(CFSocketGetNative(_socket),Sol_SOCKET,SO_REUSEADDR,(voID *)&optVal,sizeof(optVal));        struct sockaddr_in addr4;    memset(&addr4,sizeof(addr4));    addr4.sin_len = (__uint8_t)sizeof(addr4);    addr4.sin_family = AF_INET;    addr4.sin_port = htons(2115);    addr4.sin_addr.s_addr = htonl(INADDR_ANY);    CFDataRef address = CFDataCreate(kcfAllocatorDefault,(UInt8 *)&addr4,sizeof(addr4));        if (kcfSocketSuccess != CFSocketSetAddress(_socket,address)) {        if (_socket) CFRelease(_socket);        _socket = NulL;        return 0;    }        CFRunLoopRef cfRunLoop = CFRunLoopGetCurrent();    CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(kcfAllocatorDefault,_socket,0);    CFRunLoopAddSource(cfRunLoop,source,kcfRunLoopCommonModes);    CFRelease(source);        return 1;}voID* serverThread(voID* context) {    @autoreleasepool {        int res = setupSocket();        if (!res) {            return 0;        }        CFRunLoopRun();        return (voID*)1;    }}int startScreenServer() {    pthread_t tID;    return pthread_create(&tID,serverThread,NulL);}

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的远程获取iOS设备的屏幕截图全部内容,希望文章能够帮你解决远程获取iOS设备的屏幕截图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1107959.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存