当前位置:编程学习 > wap >>

文件,文件夹问题

IOS 获取 Document 文件夹路径


NSFileManager *fileManager = [NSFileManager defaultManager];

    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,                                                                          NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.png"];

IOS调取摄像头并拍照
<UIImagePickerControllerDelegate>


1、打开摄像头

- (IBAction)Open:(id)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        NSArray *temp_MediaTypes = [UIImagePickerControlleravailableMediaTypesForSourceType:picker.sourceType];

        picker.mediaTypes = temp_MediaTypes;

        picker.delegate = self;

        picker.allowsImageEditing = YES;

    }

    [self presentModalViewController:picker animated:YES];

    [picker release];

}

2.拍照回调


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

     NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

     BOOL success;

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSError *error;

  

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

  

    if ([mediaType isEqualToString:@"public.image"]){

      

        UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

        NSLog(@"found an image");

       NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:@"temp.jpg"];

        NSLog(@"%@", imageFile);

        success = [fileManager fileExistsAtPath:imageFile];

        if(success) {

            success = [fileManager removeItemAtPath:imageFile error:&error];

        }

      

        imageView.image = image;

        [UIImageJPEGRepresentation(image, 1.0f) writeToFile:imageFile atomically:YES];

         //SETIMAGE(image);

        //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);

    }

    else if([mediaType isEqualToString:@"public.movie"]){

        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

        NSLog(@"%@", videoURL);

        NSLog(@"found a video");

        NSData *videoData = [NSData dataWithContentsOfURL:videoURL];

   

        NSString *videoFile = [documentsDirectory stringByAppendingPathComponent:@"temp.mov"];

        NSLog(@"%@", videoFile);

        success = [fileManager fileExistsAtPath:videoFile];

        if(success) {

            success = [fileManager removeItemAtPath:videoFile error:&error];

        }

        [videoData writeToFile:videoFile atomically:YES];

        //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);

        //NSLog(videoURL);

    }

    [picker dismissModalViewControllerAnimated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

       [picker dismissModalViewControllerAnimated:YES];

}

IOS下载文件(同步下载)


NSString *urlAsString = @"http://files.cnblogs.com/zhuqil/UIWebViewDemo.zip";

    NSURL    *url = [NSURL URLWithString:urlAsString];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    NSError *error = nil;

   NSData* data= [NSURLConnection sendSynchronousRequest:request returningResponse:nilerror:&error];

    /* 下载的数据 */

    if (data != nil){

        NSLog(@"下载成功");

        if ([data writeToFile:@"/Users/jilucky/UIWebViewDemo.zip" atomically:YES]) {

            NSLog(@"保存成功.");

        }

        else

        {

            NSLog(@"保存失败.");

        }

    } else {

        NSLog(@"%@", error);

    }

IOS震动效果
AudioToolBox.framework

#import "AudioToolbox/AudioToolbox.h"
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

IOS获取设备号


    UIDevice *device = [UIDevice currentDevice];//创建设备对象

    NSString *deviceUID = [[NSString alloc] initWithString:[device uniqueIdentifier]];

    UIAlertView *view = [[UIAlertView alloc]initWithTitle:nil message:deviceUID delegate:selfcancelButtonTitle:@"ok" otherButtonTitles: nil];

    [view show];

Unity 3D截屏

1.js脚本(添加到ARCamera上)


#pragma strict

function Start () {}

function Update () {}

function ScreenImage(){

Application.CaptureScreenshot("Scr

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,