I am creating a app in which when the app is in background and user changes the volume in iPhone app should came to know about it.
Any ideas or clues?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
LoginVC *login=[[LoginVC alloc]initWithNibName:#"LoginVC" bundle:nil];
self.navigate=[[UINavigationController alloc]initWithRootViewController:login];
[self.window addSubview:navigate.view];
[login release];
[self.window makeKeyAndVisible];
return YES;
}
- (void)volumeChanged:(NSNotification *)notification
{
float volume =
[[[notification userInfo]
objectForKey:#"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
NSLog(#"chfi");
// Do stuff with volume
}
I Have Used This code But its not getting Called.
You can set a listener. When volume changed, the call back method will be getting called.
Related
Could any-one please explain me....it's possible in iphone. if yes then could you explain step by step because i am new in iphone development.
The closest you could do would be to have a png image as the splash which contains the 1st frame of the video you want to play and then play a video ASAP.
Some basic code to get you started might look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playBackDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"clip" withExtension:#"m4v"];
MPMoviePlayerViewController *viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:URL];
viewController.moviePlayer.fullscreen = YES;
viewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[viewController.moviePlayer play];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)playBackDidFinishNotification:(NSNotification *)notification;
{
self.window.rootViewController = [[PSRootViewController alloc] init];
}
Hi when using autolayout on iOS 6, my "rootView" of my rootViewController doesnt seem to resize properly if at all.
My rootViewController is loaded from a nib and i am adding it to the view-hierarchy like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
RootVC *rootVC = [[RootVC alloc] initWithNibName:#"RootVC" bundle:nil];
self.window.rootViewController = rootVC;
return YES;
}
But when i rotate the simulator the view of rootVC doesnt resize. Since you cant set any constraints to the "rootview" in a xib, I also tried this but without any effect:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
RootVC *rootVC = [[RootVC alloc] initWithNibName:#"RootVC" bundle:nil];
self.window.rootViewController = rootVC;
NSArray *vConst = [NSLayoutConstraint constraintsWithVisualFormat:#"V:|[view]|" options:0 metrics:nil views:#{#"view" : rootVC.view}];
NSArray *hConst = [NSLayoutConstraint constraintsWithVisualFormat:#"H:|[view]|" options:0 metrics:nil views:#{#"view" : rootVC.view}];
[self.window addConstraints:vConst];
[self.window addConstraints:hConst];
return YES;
}
When i log-out the frame-size of the rootvc's view, it's always the portrait-format (w:768, h:1024)
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
NSLog(#"%f, %f", self.view.frame.size.width, self.view.frame.size.height);
}
could someone please tell me what i'm missing here? i've wasted hours with this problem and got nowhere^^
thx
It seems that a lot of things can go wrong with the autolayout feature iOS 6. Ambiguities in the constraints and failing to disable the translatesAutoresizingMaskIntoConstraints in your view controllers can cause much conflict. So ensure there is no ambiguities in the constraints by calling the autolayoutTrace method in lldb: po [[UIWindow keyWindow] _autolayoutTrace]
If there are ambiguities, you must resolve them.
I am working with UILocalNotification.Here When i Launch the notification i need a specific view in application.But I have tried like below coding .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication]setStatusBarHidden:NO];
SplashView *mySplash = [[SplashView alloc] initWithImage:
[UIImage imageNamed:#"Splash.png"]];
[window insertSubview:mySplash atIndex:1];
[window makeKeyAndVisible];
mySplash.delay = 5;
mySplash.animation = SplashViewAnimationFade;
[mySplash startSplash];
[self.window insertSubview:viewController.view atIndex:0];
[self.window makeKeyAndVisible];
[mySplash release];
// Add the view controller's view to the window and display. [self.window addSubview:viewController.view];
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification)
{
NSLog(#"Notification Body: %#",localNotification.alertBody);
NSLog(#"%#", localNotification.userInfo);
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
showItemContrller = [[Showitem alloc] initWithNibName:#"Showitem" bundle:nil];
[self.window addSubview:showItemContrller.view];
[self.window bringSubviewToFront:showItemContrller.view];
}
}
But When i launch the notification it is showing the previous view for fraction of seconds the it is going to showItemControllerView.
Thanking you
//comment this line....
//[self.window insertSubview:viewController.view atIndex:0];
I have found here a similar old post:
showsUserLocation does not display blue dot in iPhone 4.0
I have this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
locationManager=[[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//[locationManager startUpdatingLocation];
mapView.showsUserLocation=YES;
NSLog(#"bool: %d", [mapView showsUserLocation]);
// Override point for customization after application launch.
self.viewController = [[[WhereamiViewController alloc] initWithNibName:#"WhereamiViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Why does NSLog(#"bool: %d", [mapView showsUserLocation]) show 0, not 1? Why can't I set it to YES?
You application may have finished launching but maybe your view has not loaded. If the view hasn't loaded the mapView that is within it won't have either. Try moving the showsUserLocation code to viewDidLoad
I have a project to play videofile through MPMoviePlayerViewController,
that process i was finished.in MPMoviePlayerViewController, how i add button like conrols.
MPMoviePlayerViewController is just like any other view controller. You should be able to set up your own custom view and then hook up your buttons to the moviePlayer contained in the MPMoviePlayerViewController
are you want to creating the customization of the MPMovieViewController for that below code is use to create the customized Moviecontroller..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
MainScreenVCtr *tempVariable=[[MainScreenVCtr alloc] initWithNibName:(UI_USER_INTERFACE_IDIOM())?#"MainScreeniPad":#"MainScreenVCtr" bundle:nil];
self.nvCtr=[[UINavigationController alloc] initWithRootViewController:tempVariable];
self.nvCtr.view.frame=CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height-20);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self.window addSubview:self.nvCtr.view];
self.vCtr=[[CustomControllsVCtr alloc] initWithNibName:(UI_USER_INTERFACE_IDIOM())?#"CustomControllsiPad":#"CustomControllsVCtr" bundle:nil];
[self.window makeKeyAndVisible];
return YES;
}
And refer the reference link and Download the source code and implementation tutorail given here.
Hope this tutorial help to you create customized MPViewcontroller .
Happy Codeing