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.
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?
Is there a way to present a alert like the alert presented by twitter SDK if no account is signed-in.
I want to display that type of alert if user has disabled Settings->Notification Center for my app.
Just want to present the alert, mentioned twitter as ref. Its not about twitter.
NOTE: I don't want to display / use social media, its for reference, question is can we display a custom alert which can navigate the user to settings app of iOS.
There is no way to know the status of the switch in Notification Center > Your app. The only thing you can access is what type of notifications he will get ([[UIApplication sharedApplication] enabledRemoteNotificationTypes];).
You can know notification setting of your app and can show alert when it is disable as below
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (!(types & UIRemoteNotificationTypeAlert)) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:#"TITLE" message:#"YOUR MESSAGE" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:#"Settings",nil];
[al show];
[al release];
}
For more reference, you may check Determine on iPhone if user has enabled push notifications
The only settings you can access are your app's settings, which can be within your app or in Settings app. Your app's settings are the ones you set/get with [NSUserDefaults standardUserDefaults]. However for your case you could schedule a notification which fires after one second, and see if you get called from - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification. Here is an example code.
-(void) createLocalNofication{
UILocalNotification *local = [[UILocalNotification alloc] init];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0f];
local.alertBody = #"Some Alert Body";
local.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:local];
}
- (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification {
//Here you can set some flag
}
To gain more insight on the topic, you can check out this apple documentation link.
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 .
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.