星期三, 1月 18, 2017

[Objective-c] iOS 基本技能: 呼叫相機

超常用的iOS呼叫相機基本技能,測試完記錄一下。

使用UIImagePickerController (簡單、快速)

- (void) initCamera{
    
    NSLog(@"initCamera");
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        
        //檢查是否支援此Source Type(相機)
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            NSLog(@"Access Camera Device");
            
            //設定影像來源為相機
            imagePicker.sourceTypeUIImagePickerControllerSourceTypeCamera;
            imagePicker.delegate = self;
            imagePicker.allowsEditing = YES;
            
            //顯示UIImagePickerController
            [self presentViewController:imagePicker animated:YES completion:nil];
        }
        else {
            //提示使用者,目前設備不支援相機
            NSLog(@"No Camera Device");
        }

    });
    
}

//使用者按下確定時
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //取得剛拍攝的相片(或是由相簿中所選擇的相片)
    UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
    
    //設定ImageViewImage物件,例如:
    //yourImageView.image = image;
    
    [picker dismissViewControllerAnimated:YES completion:^{}];
}

//使用者按下取消時
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    //一般情況下沒有什麼特別要做的事情
    
    [picker dismissViewControllerAnimated:YES completion:^{}];

}


使用AV Foundation

優點就是彈性比較大,速度快

[Objective-C] 初試一下 youtube live streaming (二) 實作步驟

找到幾篇有關於直播的教學,但都2014了,還是可以參考一下。
以下簡述使用Youtube直播步驟



http://yhsiang.logdown.com/posts/2014/04/16/stream-to-youtube-with-live-streaming-api

https://youtube-eng.googleblog.com/2014/10/watchme-live-stream.html

http://justinyang1221.blogspot.tw/2014/10/live-stream-youtubestreaming-to-youtube.html

星期六, 1月 14, 2017

[ubuntu] 搞壞了sudo...must be owned by uid 0 and have the setuid bit set


sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

XD不小心下錯了chown的指令,然後sudo就爆了。
搞了一小時還是沒弄好機器,
還是重裝VM的存檔-,,-
有招一日再來研究研究

http://ithelp.ithome.com.tw/articles/10053821
https://my.oschina.net/cxz001/blog/297404
http://unix.stackexchange.com/questions/16962/how-to-get-back-sudo-on-ubuntu

星期四, 1月 05, 2017

[Objective-C] AVPlayer 操作筆記

測試一下用Objective-C播放影片的sample

Sample檔放到專案

前面二個項目要打勾

取得應用程式目錄的檔案


//NSBundle resourcePath


    NSString *filePath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"SampleVideo_360x240_30mb.mp4"];


//NSBundle URLForResource


 NSURL *sourceMovieURL = [[NSBundle mainBundle]URLForResource:@"SampleVideo_360x240_30mb" withExtension:@"mp4"];

   

星期四, 12月 29, 2016

[Objective-C] Youtube Oauth2 實作

記錄一下第一次寫iOS如何與Youtube Oauth2串接

首先要申請API KEY跟Oauth要用的Client ID


Oauth2的驗證url記錄 

https://accounts.google.com/o/oauth2/auth?client_id=<你的CLIENTID>.apps.googleusercontent.com&redirect_uri=http://localhost&scope=https://www.googleapis.com/auth/youtube&response_type=code&access_type=offline

403的爆炸

用webview直接丟Oauth2的連結,google會爆給你不允許存取的403 (disallowed_user-agent)



所以改用NSURLSession來處理request,在把結果丟給webview來呈現
成功後你會取得一個auth code: 例如


http://localhost/oauth2callback?code=

[Objective-C] 剛轉入寫iOS Objective的一些簡單筆記~

記錄一下菜到不行的初學者(我本人XD)Objective-C 寫的筆記

變數宣告strong跟weak


用segue轉到另一個view如何退上去的方法

[self dismissViewControllerAnimated:true completion:nil];


用Navigation控制轉viewController

By using below line we can go to parent view controller

[self.navigationController popViewControllerAnimated:YES];


By using below line we can move to main/root view controller

[self.navigationController popToRootViewControllerAnimated:YES];


By using below line we can move to any view controller

[self.navigationController popToViewController:viewControllerObject animated:YES];

其他你感興趣的文章

Related Posts with Thumbnails