I have implement Wikitude SDK and I manage to initialize using this code:
-(IBAction)launchAR:(id)sender{
wikitudeAR = [[WikitudeARViewController alloc] initWithDelegate:self applicationPackage:nil applicationKey:nil applicationName:nil developerName:nil];
}
- (void) verificationDidSucceed {
BuddyFinderAppDelegate *appDel = (BuddyFinderAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDel.window addSubview: [wikitudeAR start]];
[window makeKeyAndVisible];
}
How I will go back to my MainViewController View?
(I want to call it from object "custombutton")
I guess your WikitudeARViewController delegate is application delegate.
1) Implement your own View controller , from where you want to launch AR Browser (on button click , preferably).
2) Instantiate WikitudeARViewController from your ViewController(button event) and making ViewController as delegate.
3) make view returned from [wikitudeAR start] to the ViewController.view (and not window.view).
Hope this helps.
you can use CustomMenuButtonDelegateImpl1.m
#implementation CustomMenuButtonDelegateImpl1
- (void) customMenuButtonPressed:(WTPoi *)currentSelectedPoi {
//NSLog(#"addpoi");
[[WikitudeARViewController sharedInstance] hide];
[UIApplication sharedApplication].statusBarHidden = NO;
}
#end
and it woroks very well
Related
OK, so I'm trying to show Apple Game Center Leaderboards called from within my cocos2d game.
I've had some trouble doing so.
I did eventually stumble upon this and I implemented the following in one of my CCScene classes (I slightly modified the original code to prevent a compiler warning).
- (void)showLeaderboardForCategory:(NSString *)category
{
// Create leaderboard view with default Game Center style
leaderboardController = [[GKLeaderboardViewController alloc] init];
// If view controller was successfully created...
if (leaderboardController != nil)
{
// Leaderboard config
leaderboardController.leaderboardDelegate = self; // leaderboardController will send messages to this object
leaderboardController.category = category;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
// Create an additional UIViewController to attach the GKLeaderboardViewController to
vc = [[UIViewController alloc] init];
// Add the temporary UIViewController to the main view
[[CCDirector sharedDirector].view.window addSubview:vc.view];
// Tell UIViewController to present the leaderboard
[vc presentModalViewController:leaderboardController animated:YES];
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[vc dismissViewControllerAnimated:YES completion:nil];
}
And, it works! At least when I call it, it does display the Leaderboard properly.
The only problem is, when I tap "Done" on the Leaderboard and the modal view dismisses, my CCScene no longer responds to tap events.
What do I need to do to regain responsiveness?
Refer sample plain cocos2d project:
-(void)showLeaderboard
{
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.leaderboardDelegate = self;
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentModalViewController:leaderboardViewController animated:YES];
[leaderboardViewController release];
}
Delegate Function:
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] dismissModalViewControllerAnimated:YES];
}
I am using MSNavigationPaneViewController from here and have rotation sort of working.
I've overridden the rotation methods in my root UINavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
which I push the MSNavigationPaneViewController with using presentViewController: animated:completion: and I have rotation working so certain views can have different orientations. The problem is, each view that has a different orientation needs the user to tilt the phone to change the orientation at which point it locks on the correct orientation.
I've done tons of reading to get this working and it seems I need preferredInterfaceOrientationForPresentation to fire before each view is loaded, but it's not firing.
I think it's not firing because the MSNavigationPaneViewController isn't changing view controllers using presentViewController.
This is the code used by MSNavigationPaneViewController to change the view
- (void)setPaneViewController:(UIViewController *)paneViewController
{
if (_paneViewController == nil) {
paneViewController.view.frame = _paneView.bounds;
_paneViewController = paneViewController;
[self addChildViewController:_paneViewController];
[_paneView addSubview:_paneViewController.view];
[_paneViewController didMoveToParentViewController:self];
} else if (_paneViewController != paneViewController) {
paneViewController.view.frame = _paneView.bounds;
[_paneViewController willMoveToParentViewController:nil];
[self addChildViewController:paneViewController];
void(^transitionCompletion)(BOOL finished) = ^(BOOL finished) {
[_paneViewController removeFromParentViewController];
[paneViewController didMoveToParentViewController:self];
_paneViewController = paneViewController;
};
[self transitionFromViewController:_paneViewController
toViewController:paneViewController
duration:0
options:UIViewAnimationOptionTransitionNone
animations:nil
completion:transitionCompletion];
}
}
which looks like it's just switching the viewController and therefor not calling preferredInterfaceOrientationForPresentation
Is there any way to force preferredInterfaceOrientationForPresentation to be called, or to trick it into be called maybe by a hidden view?
Thanks
EDIT ----
I totally understand how the new rotation system works in iOS6 and that it's down to the root to manage it. However preferredInterfaceOrientationForPresentation only seems to be called if the next view is being presented with one of the correct methods. Not if the window is just switched.
So I do actually need a way to trick this to be called.
You can trick the window into re-valuating its supported interface orientations by resetting its rootViewController.
UIApplication *app = [UIApplication sharedApplication];
UIWindow *window = [[app windows] objectAtIndex:0];
UIViewController *root = window.rootViewController;
window.rootViewController = nil;
window.rootViewController = root;
You'd need to make sure that when this code executes, -supportedInterfaceOrientations of the root view controller returns the proper mask (corresponding to how you want to force the orientation).
Be aware, this hack can cause a quick flash on the screen and glitch any ongoing animations.
preferredInterfaceOrientationForPresentation will not be called on controllers within a UINavigationController.
You are going to have to subclass UINavigationController and then implement this feature yourself. You'd simply want to delegated to topViewController.
For reference check out: http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller
I also found this implementation of a UINavigationController subclass: https://gist.github.com/3842178
Hi i am facing a strange problem. I have a class which is NSObject type, and on same class i want to share image on Facebook and Email and also on Twitter. I successfully done FB and Email, On Email i use [[[UIApplication sharedApplication] keyWindow] addSubview:mailer.view]; to show Mail controller onto Window instread of Presenting Model view controller and same as on Dismiss i use Remove from super view. But when i do same with twitter controller then twitter controller just show me few mili seconds and then hide. I also add new View controller onto Window and then Present its controller onto that View controller but same output. Don't know what going wrong. Please help on that. Thanks in advance. This will be great for me :)
Edited
if (_engine != nil) {
_engine = nil;
[_engine release];
}
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate: self];
if (controller) {
NSLog(#"Sharing on Twitter on loading controller of twitter");
[[UIApplication sharedApplication].keyWindow addSubview:controller.view];
}
else {
NSLog(#"Sharing on Twitter in else condition");
[self sharetoTwitter:screenImg];
}
ShareToTwitterMethod
- (void) sharetoTwitter:(UIImage *)img {
NSString *response = [_engine _uploadImage:img requestType:MGTwitterPublicTimelineRequest responseType:MGTwitterStatus];
NSLog(#"twitter post notification");
}
I used Add subview to load view instead of Presenting View.
Have you tried this
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window addSubView:controller.view];
[window makeKeyAndVisible];//important line dont forget to set this line
I am new to iPhone programming and trying to grasp the concept of RootViewController.
Scenario:
I have 3 views
RootViewController - Parent View
SportsViewController - Sub View 1
CricketViewController - Sub View 2
Both the subview have to be in FullScreenMode, so tab-bar or navigation bar cannot be used.
At first, Sub View 1 is loaded which is having some content and a DONE button on it.
Once user press DONE button then Sub View 1 has to be unloaded and RootViewController should load the Sub View 2.
Query
I have successfully displayed SubView 1 and when user taps on DONE then I can unload it. But I did n't get how should I notify the RootViewController from Sub View 1 that Sub View 1 has unloaded and now it should load the Sub View 2?
Thanks in Advance
Paras Mendiratta
I think the easiest solution here is to use UINavigationController and just hide the navigation bar. You can use -setNavigationBarHidden:animated: to hide (or show) the nav bar.
one way is to implement a method like - (void)loadSecondView which does all u want to do when first view is unloaded. and then int doneButtonClicked-method u call this method like this: [super loadSecondView]; and also remove first view from superview.
I assume that the screen with the "Done" button is some kind of login screen. You actually do not need all the view controllers you have defined to do what you want.
Instead you could do like this:
At application launch set CricketViewController as the root view controller.
Immediately let CricketViewController present `SportsViewController" as a modal view controller, no animation.
As far as the user is concerned the sports view controller is the starting point.
Dismiss the modal view controller on the Done button tap, giving the user the illusion of going to the next view.
view1 = [[View1 alloc] initWithNibName:#"View1" bundle:nil]; //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view1 = navigationController1;
[window addSubview:view1.view];
[window makeKeyAndVisible];
This is general idea so please change according to your problem.
Here is my code where I tried to use delegate pattern.
The problem is the sub view 1 (videoPlayer) is not able to call the delegate methods. :(
ViewSwitcher.h - Root Controller
#class VideoPlayer; //Sub View 1
#class LandingPage; //Sub View 2
#protocol viewSwitcherDelegate
-(void)notifyViewSwitcher;
#end
#interface ViewSwitcher : UIViewController
{
id <viewSwitcherDelegate> delegate;
}
#property (nonatomic, retain) VideoPlayer *videoPlayer;
#property (nonatomic, retain) LandingPage *landingPage;
#property(assign) id <viewSwitcherDelegate> delegate;
-(void)loadSecondView;
-(void)delegateSetInSubView;
#end
ViewSwitcher.m - Implementation
#synthesize videoPlayer;
#synthesize landingPage;
//#synthesize delegate;
// 1.4 -> Declare the delegate constructor
- (id <viewSwitcherDelegate>)delegate
{
return delegate;
}
// 1.5 -> Declare the setDelegate method
- (void)setDelegate:(id <viewSwitcherDelegate>)v
{
delegate = v;
}
- (void)viewDidLoad
{
VideoPlayer *videoController = [[VideoPlayer alloc] initWithNibName:#"VideoPlayer" bundle:nil];
self.videoPlayer = videoController;
[self.view insertSubview:videoController.view atIndex:0];
[videoController release];
[super viewDidLoad];
}
-(void)loadSecondView
{
NSLog(#"Call for loading 2nd View");
}
VideoPlayer.h - SubView 1 (Movie Player)
#interface VideoPlayer : UIViewController <viewSwitcherDelegate>
{
ViewSwitcher *viewSwitcher;
MPMoviePlayerController *videoController;
}
#end
VideoPlayer.m - implementation
-(void)notifyViewSwitcher
{
NSLog(#"notifyViewSwitcher called.");
//Attempted to call the loadSecondView of ViewSwitcher
I tried calling delegate's method but in log nothing is printed.
[viewSwitcher loadSecondView];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
// Setting the delegate
viewSwitcher.delegate = self;
return self;
}
- (void)viewDidLoad
{
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"bumper.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
videoController = [[MPMoviePlayerController alloc] initWithContentURL:url];
videoController.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:videoController.view];
videoController.view.frame = CGRectMake(0, 0, 480, 320);
videoController.fullscreen = YES;
// Remove the status bar from this view.
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:UIStatusBarAnimationFade];
// TODO: This observer needs to be removed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateChange:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoController];
// Play the video.
[videoController play];
[super viewDidLoad];
}
// Receives notification once movie is finished.
-(void)playbackStateChange:(NSNotification*)notification
{
// TODO: Switch the view.
NSLog(#"Notification = %#", notification);
[self notifyViewSwitcher];
}
Here is the LOG:-
2011-08-03 02:44:47.333 My Video Player[24016:207] Notification = NSConcreteNotification 0x5768280 {name = MPMoviePlayerPlaybackDidFinishNotification; object = <MPMoviePlayerController: 0x5740940>; userInfo = {
MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 0;
}}
2011-08-03 02:44:47.337 My Video Player[24016:207] notifyViewSwitcher called.
I want to convert a CGPoint from my UIView to UIWindow coordinates and have realized that UIApplication keyWindow is always nil; why is this?
I have tried the convertPoint:toView: method from UIView.
Please see this sample code I tried in the view controller in a template of Xcode (View application):
- (void)viewDidLoad {
[super viewDidLoad];
UIView *test = [[UIView alloc] initWithFrame:CGRectMake(40,40,250,250)];
[test setBackgroundColor:[UIColor redColor]];
[self.view addSubview:test];
CGPoint p = CGPointMake(100, 100);
CGPoint np;
np = [test convertPoint:p toView:[[UIApplication sharedApplication] keyWindow]];
NSLog(#"p:%# np:%#", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
AppDelegate *appDel = (AppDelegate *)[UIApplication sharedApplication].delegate;
np = [test convertPoint:p toView:[appDel window]];
NSLog(#"p:%# np:%#", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
np = [test convertPoint:p toView:nil];
NSLog(#"p:%# np:%#", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
[test release];
if(![[UIApplication sharedApplication] keyWindow])
NSLog(#"window was nil");
}
and I get:
p:{100, 100} np:{100, 100}
p:{100, 100} np:{140, 160}
p:{100, 100} np:{100, 100}
window was nil
I can convert it but only when I access the window through the app delegate. And not UIApplication. According to the documentation, keyWindow should work here, but is nil.
Why is this?
This code was executed before [window makeKeyAndVisible]; which is inside the app delegate.
So, no wonder why keyWindow was nil yet.
Easiest way is to get the window from the app delegate instead:
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
// Do something with the window now
I noticed that after having started the Guided Access, the keyWindow property on [UIApplication sharedApplication] appears to be nil.
It happened to me only on iOS7 when starting the Guided Access Mode for the first time after having enabled it in Settings > General > Guided Access, so the starting GAM view is actually displayed and not by-passed.
Since this Apple API seems buggy, I solved using the following code to retrieve the window I'm looking for.
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count]) {
return windows[0];
}
return nil;
Instead of
[[UIApplication sharedApplication] keyWindow];
maybe you could also try using
[[[UIApplication sharedApplication] delegate] window];
as iWasRobbed pointed out but it wasn't working for me as the rootViewController property isn't reachable this way.
Try this, first get the UINavigationController handle, and then the topViewController
let navController = window?.rootViewController as! UINavigationController
let yourMainViewController = navController.topViewController as! ItemsViewController
or
let yourMainViewController = navController.viewControllers.first as! ItemsViewController