@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 }
Loading images in UIWebview - Page not found example iOS/Unity Example
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)