i m trying to customize notification view, like when we receive default notification its displaying 'DOT' symbol, but i want below image format, here i attached whatever i required notification in my app. pls help me any body knows,
under didReceiveRemote Notification i wrote, like below
mv1 = [[mv alloc]init];
NSLog(#"test%#",userInfo);
[mv1 displayItem:userInfo]; // custom method
imgview.image=[UIImage imageNamed:#"img1.jpeg"];
// NSMutableDictionary *test = [userInfo objectForKey:#"aps"];
// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Message" message:[test objectForKey:#"alert"] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
// [alert show];
//[[NSNotificationCenter defaultCenter] postNotificationName:#"pushNotification" object:nil userInfo:userInfo];
You cant customize notification centre. Because it is related with the OS not a part of your app. Apple wont allow this customization .
Related
I have written a function to login to a web service using objective c
- (void) registerAck: (NSNotification *) notification {
NSLog(#"Detected callback for register");
NSString *status = [[notification userInfo] valueForKey:#"result"];
if([status rangeOfString:#"Successful"].location != NSNotFound){
//succesfully registered
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Thank you for registering. Please login using the created details"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(#"%#", status);
}
I want to know how I would go about clearing the page and then when the user selects ok on my popup chaining the page to a different one?
The clear page is easy, I would just write a method and then call this before alert[show] but the change of page is where I am stuck - can anyone let me know how I could redirect to a login page programatically?
I am using location services on background in my app for fetching user location.
I want to get local notifications from my application when the user switches off the location services in settings page.
Thanks in advance!!!!
Try This :
It's called every time user disable/enable location services in settings
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
Why you want to use local notification? Why not UIAlertView?
I would like to suggest you to use UIAlertView as it will inform the user what to do when he/she opens the app. For local notification, you can schedule it. Most likely, the user will not see the notification when the user is on the foreground of the app (when open). And you are not able to know if the app has the right to use location or not if the user never opens the app.
By using didFailWithError delegate method from locationManager, you will be able to know if the user allows your app to get the location or not.
You will have to implement the locationManager delegate method like below:-
- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error
{
switch([error code])
{
case kCLErrorNetwork: // general, network-related error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Network Error" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
case kCLErrorDenied:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"YOUR APP NAME doesn't work without Location Services enabled. To turn it on, go to Settings > Privacy > Location Services" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
default:
{
}
break;
}
}
If you insist want to implement local notification, replace the above UIAlertView with local notification code.
Recently I am trying to create an alarm clock, and when I use UILocalNotification, the problem occur. It will show a banner when the app is in background, but when the app is active, even thought I have used didReceiveLocalNotification, there is no reaction at all.
Why?
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = application.applicationState;
if (state == UIApplicationStateActive) {
NSLog(#"RingRingRing~~~~~");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Remind" message:notification.alertBody delegate:self cancelButtonTitle:#"Sure" otherButtonTitles:nil, nil];
[alert show];
}
}
Neither Remote or local notifications does not wakeup the application in iOS. it takes a user's action on the notification to launch the app.
I implemented a local notification in my game app that fires up once a day for a daily bonus. It all works fine when I tap the notification banner, however, when i get in to the app from the app icon, the local notification doesn't work like it should.
Here is my code:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{
.......
.......
application.applicationIconBadgeNumber = 0;
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
NSLog(#"recieved notification %#",localNotif);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Daily Bonus"
message:#"You recieved 100 free coins"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"ok", nil];
[alert show];
[alert release];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
float balance = [standardUserDefaults floatForKey:kCurrentScore];
balance +=100.0f;
NSLog(#"%g",balance);
[standardUserDefaults setFloat:balance forKey:kCurrentScore];
[standardUserDefaults synchronize];
}
I would appreciate any help.
That's the way it works.Starting the app from it's icon will not trigger any notifications to your app, only from the banner.You should probably use the same logic as the one triggering your notification if you want to reward your users even though they didn't tap the banner - just calculate how long has it been since the app was last ran and do your stuff there.
I have successfully used APNS in iphone app and still have a problem the alert customization.Below is my question:
1 I can't custom the Alert view,like title and button title.I custom the alert like:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *apsDic = [userInfo valueForKey:#"aps"];
NSString *alertStr = [apsDic valueForKey:#"alert"];
NSNumber *badgeNum = [apsDic valueForKey:#"badge"];
NSString *soundStr = [apsDic valueForKey:#"sound"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[arr objectAtIndex:1]
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"view",nil];
[alert show];
[alert release];
}
In my App, the title of the alert is my app's title;and the button titles are "Close" and "View".
2 when I click the "View", is shows the launch view of my app and then it crashes.Why?
So if the alert is provided by the system which can't be customized, the view action is also under control of system. It seems there's contradiction between 1 and 2.
Any help is appreciated!
thanks
I find: if your app does not start, the apns-alert is provided by the iOS which you can't customize.