network activity indicator is not shown on iPhone (iOS 5) - iphone

just to test it I enabled the activity indicator of the status bar as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: TRUE];
//...
}
I never disable the indicator so it should always be visible, but it isn't. It is visible in the iPhone Simulator but not on the device. Why?

Please not that the application is not active when a call is made to didFinishLaunchingWithOptions. You should move this to the viewDidLoad method instead. Thus the code should look like this:
- (void)viewDidLoad {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Some other code goes here...
[super viewDidLoad];
}
Or you could put this code anywhere else where the view has been loaded. Do not forget to stop it once the data has been loaded.

Related

localNotification issues

I am sending a local notification once a process is finished and it acts just fine.
This is my code for didReceiveLocalNotification:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
CounterViewController *counterVC = [CounterViewController sharedInstance];
[counterVC notificationArrived];
}
But when the iPhone is locked those lines aren't called… What can I do to make them run in the background?
There are two method to receive local notification one is already you have implemented which is invoked while app is running & 2nd is in didFinishLaunchingWithOptions which is invoked while your app is running background you have add some code for receive local notification .....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
return YES;
}

enabling notifications

I would like to enable notifications in my iphone app. So, I modify in app ID:
After that, I generate again Development and Distribution Provisioning Profiles and installed in my xcode.
My app is a tabbed based application, the first tab is UITableViewController
I add this lines:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
So, I suppose I should have my app in the list of app installed with notifications in my iphone, but it isnt.
Did I miss some step?
Yep. According to this and this you should add the registerForRemoteNotificationTypes method in your didFinishLaunchingWithOptions, which should the look something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
Depending on which Types you registered your app will appear in the notifications section and you can turn on and off the different types (sound, badge, banner).
Hope that helps.
First enable your remote notification in app delegate. See below :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}

remoteControlReceivedWithEvent not called in multiple view controllers app

I have a App works well on iOS 4.3.3. But I found there are some problems on iOS 5. This App plays mp3 files by avaudioplayer and the remote control does not work well on iOS 5.
There are four view controllers in this App. I add following codes on each view controller in order to realize the function of remote control. The problem is, when the view controller is first time to open. The remote control button works well, even the app run in background or lock the screen. But when I click anther view controller and go back the previous on, the remote controller does not work anymore. But canBecomeFirstResponder function was called every time.
I even try to put
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
in delegate function
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
It not work.
I don't understand why this is happening. It tortured me for few days.
Is there better way to realize remote control function in multiple view controllers?
BTW, I added the UIBackgroundModes audio key to the info.plist. And this App works well well in background.
Any help will be appreciated.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL) canBecomeFirstResponder {
NSLog(#"Can be first responder!");
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(#"UIEventSubtypeRemoteControlTogglePlayPause");
[self playAndpause:nil];
}
}

How to use [[UIApplication sharedApplication] openURL:] open other app?

I followed http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html instruction to open app1(GlassButton) within app2(FontTest).
The open method of FontTest as following:
-(void)open {
BOOL res = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"glassbutton://"]];
if (res) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"glassbutton://"]];
}
}
The value of "res" is "YES", but nothing happen after openURL method be called.
The info-list of "FontTest"as following:
URL Schemes: glassbutton
URL identifier: com.yourcompany.glassbutton
I tried to open twitter and facebook apps by "twitter://" and "fb://" successfully. But I do not know why I cannot open this small app. I'm not sure whether any thing/step wrong or missing? Need I handle - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url for FontTest, if yes, how to handle it? Could you please kindly help me? Thanks in advance!
To request the launch of your app use something like this:
NSString *urlString= #"glassbutton://com.yourcompany.glassbutton";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
Then, in the glassbutton app, you'll need to handle any special behavior within the app delegate method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//your app specific code here for handling the launch
return YES;
}
Note that within the app you are opening the above delegate method will only get called AFTER the following method is called:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Handle accordingly, good luck.

How to handle a custom URL in an already-open app?

I have an app based on the Utility template (i.e. Main and Flip view controllers). The Flip view allows selecting a certain item to be used on the main view. So far - works great.
Now I tried adding a custom URL. Something to the effect of: myapp://itemID=40 that will basically tell the main view: "no need to flip - you'll be dealing with item 40".
I registered the URL type scheme as "myapp" and added the following method to the app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) {
return NO;
}
NSString *urlString = [url absoluteString];
NSLog(#"URL received: %#", urlString);
NSString *itemID = [urlString stringByReplacingOccurrencesOfString:#"myapp://itemID=" withString:#""];
NSLog(#"Item received: %#", itemID);
[_mainViewController setStartupItem:itemID];
return YES;
}
As you can see, the itemID is set to a property called startupItem in the mainViewController.
I then added one line to the regular application method to verify that startupItem will be nil in case of no URL:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Make sure URL string is empty
[_mainViewController setStartupItem:nil];
// Override point for customization after application launch.
// Add the main view controller's view to the window and display.
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
And in MainViewController.m I added code to handle the item to the viewDidLoad event.
And here's my problem: this scheme works great if the app is started from a URL the first time. If it's already running, then we never reach viewDidLoad again and therefore don't handle that particular item, but go on as if none was passed.
My humble question is: which UIViewController should I put my handling code in? Or, am I approaching all this the wrong way? Should this be handled in my model?
As always, thanks in advance for your time!
Guy
I would take a look at the docs for UIApplicationDelegate protocol, specifically;
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
And this which is deprecated.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
Well definitely not in a method that gets called only once while the application starts up! You need to refactor the item handling code in its own method, then call this method from viewDidLoad (once during startup) and handleOpenURL each time it gets called.