I made a RSS app, it works perfectly, I also added Push Notification Support, everything is good so far, am passing a title, alert, and a url as an extra field.
When my notification arrives, I show my alert, and you have 2 options "Thanx | Open"
All I want to do now is, when you click open from this alert, I need to redirect my user to a view that has a UIwebview and load the url I passed along with the notification.
Can anyone help me?
Here is my code:
// here is my app delegate
-(void)onReceivePushNotification:(NSDictionary *) pushDict andPayload:(NSDictionary *)payload {
[payload valueForKey:#"title"];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"New Alert !" message:[pushDict valueForKey:#"alert"] delegate:self cancelButtonTitle:#"Thanks !" otherButtonTitles: #"Open",nil];
NSLog(#"message was : %#", [pushDict valueForKey:#"alert"]);
NSLog(#"url was : %#", [payload valueForKey:#"url"]);
[message show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Open"]) {
[[Pushbots getInstance] OpenedNotification];
// Decrease Badge count by 1
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber -1];
// Decrease badge count on the server
[[Pushbots getInstance] decreaseBadgeCountBy:#"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"updateRoot" object:nil];
} else {
// set Badge to 0
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
// reset badge on the server
[[Pushbots getInstance] resetBadgeCount];
}
}
My detail view is called : "APPDetailViewController", with a web view called "webView"
Please help me?
Thanks in advance.
You could create an instance of APPDetailViewController in your clickedButtonAtIndex method and present it. If you have tabs, you can switch to that tab, and then have a method to pass the url to so that it opens that page.
Related
I am having much trouble trying with requesting the location services authorization. I know there are other posts on this forum, but I did not solve my problem with their solution.
This is the error popping up in xCode:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
I have added both the required keys for the Plist.
Another important point is that when I start it in the simulator, I can go into the setting manually and enable location services and then the App does work. However, when I restart the App it does not work and I get the same message above.
I want to prompt the user with the option to enable location services.
Unfortunately, this code does not prompt the authorization for location services.
Please help I have been pulling my hair out for hours.
1
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:#selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
//Initialize the map and specifiy bounds
self.myMapView =[[MKMapView alloc]initWithFrame:self.view.bounds];
//specifcy resizing
self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//show the User's location and set tracking mode
self.myMapView.showsUserLocation = YES;
self.myMapView.userTrackingMode = MKUserTrackingModeFollow;
//add the VIEW!!
[self.view addSubview:self.myMapView];
}
And here is the Function I want to call
- (void)requestAlwaysAuthorization
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
// If the status is denied or only granted for when in use, display an alert
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
NSString *title;
title = (status == kCLAuthorizationStatusDenied) ? #"Location services are off" : #"Background location is not enabled";
NSString *message = #"To use background location you must turn on 'Always' in the Location Services Settings";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Settings", nil];
[alertView show];
}
// The user has not enabled any location services. Request background authorization.
else if (status == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestAlwaysAuthorization];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Send the user to the Settings for this app
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL];
}
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
This is the delegate method about location service
You can get your AuthorizationStatus from status.Such as kCLAuthorizationStatusDenied
You simply call
[self.locationManager requestAlwaysAuthorization];in viewdid load,and monitor AuthorizationStatus in delegate method above,if user deny your location service,show a alertview
I am new to iOS.I am developing an application which contain notifications.While using the app when a notification arrives an alertView is displayed.Everything works fine but if notification arrives when another alertView is already displayed problem starts.Notification alertView is displayed above the existing alertView.When I click OK for the notification alertView UI navigates to a new view controller and there the fist alertView remains displayed.If i click on that alertView my app crashes.
Is there any way to close all the alertviews that is displayed, when I click on the notification alertView.
I got this solution
for (UIWindow* window in [UIApplication sharedApplication].windows)
{
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]])
[(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}
But this code works for iOS6 not iOS7.
I want a corresponding code in iOS7.
Can anyone please help.Thanks in advance
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"title" message:#"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert1 show];
[self performSelector:#selector(dismiss:) withObject:alert1 afterDelay:1.0];
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
I've looked around all over the place, but I haven't found a solution to this oddly specific problem. I have a UIToolbar that contains, among other buttons, one that calls a method that shows an MFMessageComposeViewController. When it's called, if the person in the Contacts list hasn't been sent a message already, then everything goes fine and dandy. However, if the person has been sent a message already, then the view controller dismisses as soon as it opens, triggering MessageComposeResultCancelled, even though the user didn't get the chance to press the cancel button. Any ideas as to why this is happening?
For good measure, here is my message sending method:
-(void) showEmailComposer {
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
//[messageVC setMessageComposeDelegate:self];
messageVC.messageComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:#"NUMBER"];
[messageVC setRecipients:toRecipients];
NSString *smsString = [NSString stringWithFormat:#"Here's a link to my current location: http://maps.apple.com/?ll=%f,%f", _lat, _lon];
messageVC.body = smsString;
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
} else {
UIAlertView *alerty = [[UIAlertView alloc]
initWithTitle: #"Unable to send Message"
message: #"Sorry, but your device is incapable of sending messages right now."
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alerty show];
}
}
I downloaded an app from app store and noticed that once I installed and opened the app, I got a UIAlertView suggesting that I download another app..
How can I achieve this? Are there any existing code that I can be directed towards?
Seems like a simple feature but I'd like to integrate it. Please see attachment
Here is my edited code, but the 'Hello' button won't link anywhere.. What am I doing wrong?
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Hello", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Hello"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"https://itunes.apple.com/gb/app/islam/id667021108?mt=8&affId=1930871&ign-mpt=uo%3D4"]];
}
}
first you have to make alertView, if you want to show the alert as first thing but this code inside (ViewDidLoad) method
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"your title"
message:#"your message"
delegate:self
cancelButtonTitle:#"Not now"
otherButtonTitles:#"Download now"
, nil];
[alert show];
after viewDidLoad but this method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"here but your application link"]];
}else{
}
}
//=================================================//
To know what's NSUserDefaults, I suggest to take a look the official doc.
And of course you can use it to fulfill your goal. You use a user default to store information about the current amount of runs in the app.
More or less like:
BOOL NotTheFirstTime = [[NSUserDefaults standardUserDefaults] boolForKey:#"NotTheFirstTime"];
if(!NotTheFirstTime){
// Show the alert view
// Then set the first run flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"NotTheFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if that help you please make it the best question.
It is pretty simple:
1) Set up an UIAlertView as usual with the text and the button titles you like.
2) Set up the UIAlertView's delegate and use this method to figure out which button was clicked (whether the user does or does not want to go to the App Store):
alertView:clickedButtonAtIndex:
3) If the user wants to go to the App Store, open up an App Store link:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"<#This is your App Store Link#>"]];
I have a UIWebController embedded in a UIViewController.
I write the HTML code for the UIViewcontroller so I have complete control over the HTML page.
When the user clicks a button in the HTML page - can the containing UIViewController be notified about it?
Can the UIWebView send/raise an event to the UIViewControler?
You need to implement the webView:shouldStartLoadRequest:navigationType: delegate method for your web view (Apple Docs).
Here's a quick example:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:#"someLinkURL"]) {
// Display alert
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"Hello" message:#"I'm a message!" delegate:self cancelButtonTitle:#"Okay!" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
return NO;
}
return YES;
}
Your VC must be the webViewDelegate for this method to work.
If you want to handle all clicks manually (i.e. don't go to other pages in the web view) return NO on that final line.