iOS UIActivity View Controller: Add To Reading List Button? - iphone

Is there a service to be able to add a URL to the iOS Safari's Reading List from in a app.
I would have a url to add and a UIWebView,but I have researched and I can't find anything.
Here is my working UIActivityViewController.
-(IBAction)actionButton:(id)sender;{
NSLog(#"shareButton pressed");
NSURL *URL = [NSURL URLWithString:self.feedItem[#"url"]];//this is your text string
NSArray *activityItems = #[URL];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
TUSafariActivity *TUSafari = [[TUSafariActivity alloc] init];
MLCruxActivity *cruxActivity = [[MLCruxActivity alloc] init];
NSArray *applicationActivities = [NSArray arrayWithObjects:TUSafari,chromeActivity,cruxActivity, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities: applicationActivities];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact];
[self presentViewController:activityVC animated:TRUE completion:nil];
}

UPDATE: iOS 7 added an API to accomplish this:
#import <SafariServices/SafariServices.h>
SSReadingList * readList = [SSReadingList defaultReadingList];
NSError * error = [NSError new];
BOOL status =[readList addReadingListItemWithURL:[NSURL URLWithString:urlToAdd] title:titleToAdd previewText:previewText error:&error];
if(status)
{
NSLog(#"Added URL");
}
else NSLog(#"Error");
Currently (iOS SDK 6.1) there is no way to add a item to the Reading List from a third party app.
There are some alternatives like Readability you could use.

Related

Search nearby in iOS Maps

I am trying to build a simple application using MapKit that will automatically search for a specific place when the app launches and drop pin(s) on the map at the locations(s). I am seeing all sorts of ways to load locations (lat/lon, etc), but nothing that lets me search for a specific business name, restaurant name, etc.
I am expecting to work with Apple Maps. However, if Google Maps would be a better solve than so be it.
Any help would be appreciated. Thanks
iOS >= 6.1 provides MKLocalSearch, MKLocalSearchRequest to search for natural language points of interest. Sample
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.region = regionToSearchIn;
request.naturalLanguageQuery = #"restaurants"; // or business name
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
// do something with the results / error
}];
i know its late but hope this helps!
[super viewDidLoad];
[self.searchDisplayController setDelegate:self];
[self.ibSearchBar setDelegate:self];
self.ibMapView.delegate=self;
// Zoom the map to current location.
[self.ibMapView setShowsUserLocation:YES];
[self.ibMapView setUserInteractionEnabled:YES];
[self.ibMapView setUserTrackingMode:MKUserTrackingModeFollow];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
[locationManager startUpdatingLocation];
[self.ibMapView setRegion:MKCoordinateRegionMake(locationManager.location.coordinate, MKCoordinateSpanMake(0.2, 0.2))];
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.region = self.ibMapView.region;
request.naturalLanguageQuery = #"restaurant";
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
results = response;
if (response.mapItems.count == 0)
NSLog(#"No Matches");
else
for (MKMapItem *item in response.mapItems)
{
NSLog(#"name = %#", item.name);
NSLog(#"Phone = %#", item.phoneNumber);
[_matchingItems addObject:item];
MKPointAnnotation *annotation =
[[MKPointAnnotation alloc]init];
annotation.coordinate = item.placemark.coordinate;
annotation.title = item.name;
[self.ibMapView addAnnotation:annotation];
}
}];
}
Make the following steps to display nearest places.
Using google API find the Nearest Places Google Places API
The google API provide LAt and Long and address Informations.
Then Store the LAt and Long Values to Array then USing this lat and long values you can display Annotations in Apple map (iOS 6+) and Google Map (iOS 5).

Can I use UIActivityViewController to share on Facebook ?

I am trying to use UIActivityViewController to share on facebook.
When I am using the
UIImage* image = [UIImage imageNamed:#"image1.png"];
NSArray* dataToShare = #[#"test",image];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
I can't see the "Share on Facebook" icon although I didn't exclude "UIActivityTypePostToFacebook". isn't there a predefined UIActivity for facebook ?
Thanks
you must be logged in your iphone settings:
Settings -> facebook
Try this: if you want only facebook icon to share:
-(IBAction)shareButtonPressed:(id)sender { NSLog(#"shareButton pressed");
NSString *texttoshare = _txt;
UIImage *imagetoshare = _img;
NSArray *activityItems = #[texttoshare, imagetoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
//in the list of excluded activity type insert any other kind of activitytypes you want to exclude

How to add different text to UIActivityViewController objects

I have implemented a UIActivityViewController, for sharing some information. In this case I have a question: Is it possible to make a different text between the facebook sharing/twitter sharing/ or mail sharing? That the text which is set is different from the others...
A good UIActivityViewController tutorial would be very useful.
My code at the time is, for displaying text and image:
NSString *text = #"Lime Cat";
UIImage *image = [UIImage imageNamed:#"MyApp Icon 512x512.png"];
NSArray *items = [NSArray arrayWithObjects:text,image , nil];
But how can I manage it that the NSString is just for the mail, and make a seperate NSString for the facebook share option?
Any suggestions?
Thanks.
you can go to the link bellow, there is a tutorial that can help you :
https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/
You can have your class conform to the UIActivityItemSource protocol and implement activityViewController:itemForActivityType:. The activityType will be FB, Twitter, Messages app, etc, so you can do a switch on it and return a different object based on the activity.
-(void)ShareImageandText:(UIButton *)sender
{
NSString *texttoshare =#"http://qrs.ly/l851gh4";
UIImage *image = [UIImage imageNamed:#"default"];
NSString *noteStr = [NSString stringWithFormat:#"Please follow this link below to install the Freedom.desi application on your IPhone. %#",texttoshare];
NSURL *url = [NSURL URLWithString:texttoshare];
NSArray *activityItems = #[noteStr,image];
NSLog(#"this %#",activityItems);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr,image] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
//if iPad
else {
// Change Rect to position Popover
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr, url] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

iPhone SMS Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilĂ  !

how to reflect changes in the database without running the app again?

I am(new to iPhone) developing an iPhone App which tracks the data Usage(wifi,cellular). I am giving an option to the user to add new plans which will be put into a table in the database(sqlite).
I am displaying the list of plans in a picker view and I want to refresh the data in the picker view as soon as user enters a new plan. As of now pickerview is getting updated in the next run :(
thanks in advance.
code is here:
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
plans= [[NSMutableArray alloc] init];
NSLog(#"Data base is entering");
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"antara" ofType:#"sqlite"];
FMDatabase *db1 = [[FMDatabase alloc] initWithPath:path1];
[db1 open];
FMResultSet *fResult2= [db1 executeQuery:#"SELECT * FROM main"];
NSLog(#"fresult2 ready");
while ( [fResult2 next])
{
planData = [fResult2 stringForColumn:#"planName"];
[plans addObject:planData];
NSLog(#"The data is =%#",planData);
}
[db1 close];
[pickerView selectRow:1 inComponent:0 animated:NO];
//mlabel.text= [plans objectAtIndex:[pickerView selectedRowInComponent:0]];
//[self setCurrentPlan:[plans objectAtIndex:[pickerView selectedRowInComponent:0]]];
//[mlabel setText:[self getCurrentPlan]];
currentPlan= [plans objectAtIndex:[pickerView selectedRowInComponent:0]];
[plan setText:currentPlan];
[pickerView release];
I think you need some separation in your code. Try this and tell me if it works
1) Take out the logic of pulling data from DB into a separate function, lets call it loadPlans.
- (void) loadPlans {
plans= [[NSMutableArray alloc] init];
NSLog(#"Data base is entering");
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"antara" ofType:#"sqlite"];
FMDatabase *db1 = [[FMDatabase alloc] initWithPath:path1];
[db1 open];
FMResultSet *fResult2= [db1 executeQuery:#"SELECT * FROM main"];
NSLog(#"fresult2 ready");
while ( [fResult2 next])
{
planData = [fResult2 stringForColumn:#"planName"];
[plans addObject:planData];
NSLog(#"The data is =%#",planData);
}
[db1 close];
}
2) Obviously this code is taken from the function you had pasted above and hence, remove these lines from that function.
3) Under normal flow: Call loadPlans before the call to the above mentioned function
4) Whenever you have something inserted in the database. Call these two functions again there
[self loadPlans];
[PickerView reloadComponent:n];
This all assumes that the db entry of the plan is happening on the same page and in the same thread so that you have control over it, where you can call these functions. If this assumption is not true then also explain how and when the plans are getting added to db, paste some code about db entry too here.
all you need to do is to trigger a rebuilding the components you are showing by
[customPickerView reloadComponent:n] // where n = the index of the component
put the trigger code somewhere after the loading has finished.
You may also use something like this to check if the pickerView is visible and if you really need to update the screen:
if ([screenUpdateDelegate respondsToSelector:#selector(whateverIneedToDo:)]) {
[screenUpdateDelegate whateverIneedToDo:withParameterIfYouLike];