Photo.php: <?php if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . " "; } else { echo "Upload: " . $_FILES["file"]["name"] . " "; echo "Type: " . $_FILES["file"]["type"] . " "; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb "; echo "Temp file: " . $_FILES["file"]["tmp_name"] . " "; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Source Unity Side: private IEnumerator UploadToPublicServer(byte[] data) { WWWForm form = new WWWForm(); form.AddBinaryData("file", data, "screenShot.png"); WWW www = new WWW("http://localhost/PhotoTest/photo.php", form); yield return www; if (www.error == null) { Debug.Log("upload done :" + www.text); } else { Debug.Log("Error during upload: " + www.error); } }
Unity 3D Convert binary data to image using PHP - Upload using WWWForm
iOS UIbutton overlay
-(void) viewDidAppear:(BOOL)animated { //*** Example*** //UIButton *pauseImg; //pauseImg =[self drawImage:pauseIcon inImage:pauseImg]; } -(UIImage*) drawImage:(UIImage*) fgImage inImage:(UIImage*) bgImage { UIGraphicsBeginImageContextWithOptions(bgImage.size, FALSE, 0.0); [bgImage drawInRect:CGRectMake( 0, 0, bgImage.size.width, bgImage.size.height)]; [fgImage drawInRect:CGRectMake( 0, 0, fgImage.size.width, fgImage.size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
iOS Screen size based on orientation
//Get current screen size based on the orientation of the device -(CGSize) currentSize { return [self sizeInOrientation:[UIApplication sharedApplication].statusBarOrientation]; } -(CGSize) sizeInOrientation:(UIInterfaceOrientation)orientation { CGFloat scale = [[UIScreen mainScreen] scale]; CGSize size = [UIScreen mainScreen].bounds.size; if (UIInterfaceOrientationIsLandscape(orientation)) { size = CGSizeMake(size.height*scale, size.width * scale); } return size; } -(void) viewDidAppear:(BOOL)animated { CGSize size = [self currentSize]; NSLog(@"%f",size.height); NSLog(@"%f",size.width); }
Loading images in UIWebview - Page not found example iOS/Unity Example
@interface WebView : NSObject<UIWebViewDelegate> { UIWebView *webView; } -(void)closeAd:(id)sender; @end UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; //if Unity use UIView *view = UnityGetGLViewController().view; webView = [[UIWebView alloc] initWithFrame:view.frame]; webView.delegate = self; webView.hidden = YES; webView.scalesPageToFit = YES; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(closeAd:) forControlEvents:UIControlEventTouchUpInside]; CGPoint topLeft = webView.frame.origin; button.frame = CGRectMake(topLeft.x, topLeft.y, 32, 32); [button setTitle:@"[X]" forState:UIControlStateNormal]; // Create URL request for image file location NSString *imageName = [[NSBundle mainBundle] pathForResource:@"404_Image" ofType:@"png"]; NSURL *imageURL = [NSURL fileURLWithPath: imageName]; NSURLRequest *imageRequest = [NSURLRequest requestWithURL: imageURL]; // Load image in UIWebView webView.scalesPageToFit = YES; [webView loadRequest: imageRequest]; // TODO animate webview when presenting [webView addSubview:button]; [view addSubview:webView]; -(void)closeAd:(id)sender { webView.hidden = YES; } //use delegates to handle on page load success and failure - (void)webView:(UIWebView *)webview didFailLoadWithError:(NSError *)error { //Show Image/Strings/HTML } - (void)webViewDidFinishLoad:(UIWebView *)webView { //do stuff }
iOS 7 Microphone request
//To prompt Microphone request at anytime [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {}]; //To detect if microphone is allowed for the application // This can be found inside privacy settings of the device -(BOOL)isMicrophonePrivacyOn { __block BOOL micStatus; if([[AVAudioSession sharedInstance] respondsToSelector: @selector(requestRecordPermission:)]) { [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { if(!granted) { micStatus = NO; } else { micStatus = YES; } }]; return micStatus; } else { return YES; } }
iOS 6+ interruption handling
//init interruption handler AVAudioSession* session = [AVAudioSession sharedInstance]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InterruptionHandler:) name:AVAudioSessionInterruptionNotification object:session]; - (void) InterruptionHandler: (NSNotification*) notification { NSUInteger type = [[notification.userInfo objectForKey:@"AVAudioSessionInterruptionTypeKey"] unsignedIntegerValue]; switch(type) { case AVAudioSessionInterruptionTypeBegan: printf_console("-> AVAudioSessionInterruptionTypeBegan()\n"); break; case AVAudioSessionInterruptionTypeEnded: { printf_console("-> AVAudioSessionInterruptionTypeEnded()\n"); break; } } }
Subscribe to:
Posts (Atom)