enabling notifications - iphone

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;
}

Related

How do I call this method that registers device

I do not know how to replace "method" with the following app delegate method.
viewcontroller
[(AppDelegate *)[[UIApplication sharedApplication] delegate] method];
appdelegate
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
TUPushHelper * helper = [[TUPushHelper alloc] initWithTokenData:devToken];
[helper registerDevice];
}
You do not need to call it programmatically. The delegate receives this message after the registerForRemoteNotificationTypes: method of UIApplication is invoked and there is no error in the registration process. didFailToRegisterForRemoteNotificationsWithError: will be called otherwise.
To register your device for remote push notifications you have to do this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
...
}
Edit:
Check Apple Guide for APNS here
also check out this tutorial

didFinishLaunchingWithOptions not called

I'm having trouble enabling push notifications.
with this code I try to enable the notification:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
It doesnt work, so I added a breakpoint in the line
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
But it seems this part of the code is never execute.
why is this not working?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This should be implemented in your UIApplicationDelegate, not in your UIViewController. If you have it in your UIViewController, it will never get called. Take the code out of there and put it in your UIApplicationDelegate instead.

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

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.

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 can I make a call, as I recieve a push notification?

I have developed an appointment application. When I receive a push notification, I want to make a call to a particular person, but right now it is just opening the application when I get a push notification.
How do I write a code to make a call to a particular appointment as I get the push notification of that appointment?
For push notification you have to code in appDelegate,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",[userInfo valueForKey:#"phno"]]]];
}
For local notification,
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",[notification.userInfo valueForKey:#"phno"]]]];
}
Upon notification, open the dialer app with the given phone number. Note: this will initially launch your app, then quickly switch to the dialer.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://5555555555"]];
}