Add an integer to UIActivityViewController? - ios

I would like to add an integer to a UIActivityViewController, yet it is not working. Here is my code:
- (IBAction)socialButton:(id)sender {
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
NSArray *itemsToShare = #[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFlickr, UIActivityTypePostToTencentWeibo, UIActivityTypePostToWeibo, UIActivityTypePostToVimeo];
[self presentViewController:activityVC animated:YES completion:nil];
}

This line:
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
needs to be:
NSString *shareText = [NSString stringWithFormat:#"I just scored %i in Helicave!", scoreNumber];

Try changing the first line,
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
to:
NSString *shareText = [NSString stringWithFormat:#"I just scored %i in Helicave!", scoreNumber];
You need to tell XCode that the string is going to have formatting, like %#, or %i, before you create the string

Related

This item cannot be shared. Please select different item WhatsApp Share Extension Failure IOS

I want to share contact by using whatsapp from my app.
I create vcf file and sent it UIActivityViewController.
However whatsapp says ; This item cannot be shared. Please select different item
I used code is that:
- (NSString *)vCardRepresentation:(NSString*)message
{
NSArray *arr=[message componentsSeparatedByString:#","];
NSString *fname,*image,*phone,*Email;
fname=[arr objectAtIndex:0];
phone=[arr objectAtIndex:1];
Email=[arr objectAtIndex:2];
image=[arr objectAtIndex:3];
NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
[mutableArray addObject:#"BEGIN:VCARD"];
[mutableArray addObject:#"VERSION:3.0"];
[mutableArray addObject:[NSString stringWithFormat:#"N:;Alper KOC;;;"]];
[mutableArray addObject:[NSString stringWithFormat:#"FN:Alper KOC"]];
[mutableArray addObject:[NSString stringWithFormat:#"TEL;type=CELL;type=VOICE;waid=905416050594:+90 541 605 0594"]];
[mutableArray addObject:#"END:VCARD"];
NSString *string = [mutableArray componentsJoinedByString:#"\n"];
return string;
}
NSString * strVCard = [self vCardRepresentation:message.message];
NSError * err;
[strVCard writeToFile:[NSString stringWithFormat:#"%#/%#",documentsDirectory,#"data.vcf"] atomically:YES encoding:NSUTF8StringEncoding error:&err];
[items addObject:[NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/%#",documentsDirectory,#"data.vcf"]]];
self.activityViewController = [[customactivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:self.activityViewController animated:YES completion:nil];
Please Use CNContactVCardSerialization For VCARD Generating.

MFMessageComposeViewController freezes before displaying the view controller

I'm having a problem where every time I click the button that calls on my MFMessageComposeViewController nothing happens. More specifically it freezes before it displays the controller and I am not able to do anything.
Here's my code:
- (IBAction)getQuote:(id)sender {
NSString * inputProduct =_productTextField.text;
NSString * inputYear = _yearTextField.text;
NSString * inputMake = _makeTextField.text;
NSString * inputEmail = email.text;
NSString * inputDescript = _descript.text;
emailConfirmation.text = email.text;
//email subject
NSString *emailTitle = #"Love Shack Electronics";
//email content
if ([conditionlabel isEqual: #"Fair"]) {
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
If anyone can help or figure out what is wrong with my code it would be greatly appreciated.
Please check in device and latest Xcode version. it's work fine. it not work then put into dispatch method like below
dispatch_async(dispatch_get_main_queue(),
^{
if ([conditionlabel isEqual: #"Fair"])
{
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
}
});

Email issue iOS8 in Simulator

I have an issue in iOS8 issue in Simulator in won't work ? can anybody help me for this ?
here message is String Message but it not appear in Mail sheet ?
Here's what i have tried !!
NSMutableString* sub = [NSMutableString string];
[message appendFormat:#"\n"];
[sub appendString:#"Item Id : "];
[sub appendString:item.item_id];
UIImage *img = self.thumbnailImageView.image;
NSMutableArray *actItems = [[NSMutableArray alloc] init];
[actItems addObject:message];
[actItems addObject:sub];
if(img != nil)
{
[actItems addObject:img];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:actItems
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter,
UIActivityTypeAirDrop];
[self.navigationController presentViewController:activityViewController
animated:YES
completion:^{}];
[activityViewController setValue:sub forKey:#"subject"];
activityViewController.popoverPresentationController.sourceView = parentView;

Cancel button action in zbar shows blank view

I am using tab bar in my iOS app. When I tap on the scan tab, i invoked the delegate method to start the camera immediately on scan tab. When I start the camera to scan the QR Code and tap on cancel button before scanning, I get the blank view. How to display the view when camera is dismissed
- (void) openCameraScanner
{
ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = YES;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentViewController:reader animated:YES completion:nil];
reader.showsZBarControls = YES;
//reader.cameraOverlayView = [self commonOverlay];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
//resultsView.text = symbol.data;
NSString *urlString = symbol.data;
NSURL *url = [NSURL URLWithString:urlString];
NSLog(#"Query after scan = %#", [url query]);
//Extract id from URL which is there in QR Code --- start
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for(NSString *param in [urlString componentsSeparatedByString:#"&"])
{
NSArray *elements = [param componentsSeparatedByString:#"="];
if([elements count]<2)
continue;
[dictionary setObject:[elements objectAtIndex:1] forKey:[elements objectAtIndex:0]];
NSLog(#"value is == %#", [elements objectAtIndex:1]);
//Extract id from URL which is there in QR Code --- end
if([[elements objectAtIndex:1] intValue])
{
NSUserDefaults *defaultsForAsk = [NSUserDefaults standardUserDefaults];
idToAsk = [NSString stringWithFormat:#"%d",[[elements objectAtIndex:1] intValue]];
[defaultsForAsk setObject:idToAsk forKey:#"IDTOASKVIEW"];
flagToShowView = YES;
listViewCntrl.getFlag = flagToShowView;
[self viewDidLoadForDynamicFields];
}
else if([elements objectAtIndex:1] == [NSNull null])
{
[reader dismissViewControllerAnimated:YES completion:Nil];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Invalid QR Code scanned" message:#"Please scan Collaborator's QR Code" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[message show];
}
}
image.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
//[reader dismissViewControllerAnimated:YES completion:nil];
[reader dismissViewControllerAnimated:YES completion:Nil];
}
You can re display the view using -(void)viewWillAppear:(BOOL)animated method of your ViewController class.

Issue With Texting From UIActivitySheet On Some Phones

My app has an action button to pull up a UIActivityViewController. On my test device 5S, it will do everything fine, including texting. However, on my 5C test device, it crashes upon trying to send a Message. Is there something wrong with my code here that would make it work with SOME phones for sending Message, and not others?
The code listed below has some caveats to it. First of all, some times, the text to be sent will be over 140 characters, so I run a check first on the length of the string. If over 140 characters, it clips out middle part, adds ... before the end, and keeps it at 140 characters. Then, on the action, if over 140 characters it sends the edited string just for Twitter and Message, but the regular string for all others, and regular string, if 140 characters or under.
-(void)sendit {
NSString *string = label1.text;
if ([string length] > 140) {
int maxChars = 140;
int charsOver = [string length] - maxChars;
NSString *replacementString = #"...";
charsOver += [replacementString length]; //account for adding "..."
NSArray *components = [string componentsSeparatedByString:#" - "];
NSMutableString *stringToTrim = [NSMutableString string];
int numberOfComponents = [components count];
for (int i = 0; i < numberOfComponents - 1; i++) {
NSString *component = [components objectAtIndex:i];
if (i < numberOfComponents - 2) {
[stringToTrim appendFormat:#"%# - ", component];
}
else {
[stringToTrim appendString:component];
}
}
NSString *trimmedString = [stringToTrim substringToIndex:[stringToTrim length] - charsOver];
self.finalString = [NSString stringWithFormat:#"%#%#%#", [trimmedString stringByAppendingString:replacementString], #" - ", [components objectAtIndex:numberOfComponents - 1]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[self] applicationActivities:nil];
activityVC.excludedActivityTypes = #[ UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypePrint,
UIActivityTypeAirDrop
];
[self presentViewController:activityVC animated:YES completion:nil];
}
else {
NSArray *activityItems = #[label1.text];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[ UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypePrint,
UIActivityTypeAirDrop
];
[self presentViewController:activityVC animated:YES completion:nil];
}
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypeMail]) {
NSLog(#"TEST");
return label1.text;
}
if ([activityType isEqualToString:UIActivityTypePostToTwitter]){
NSString *string = label1.text;
if ([string length] > 140) {
return self.finalString;
}
else {
return label1.text;
}
}
if ([activityType isEqualToString:UIActivityTypePostToFacebook]){
return label1.text;
}
if ([activityType isEqualToString:UIActivityTypeCopyToPasteboard]){
return label1.text;
}
if ([activityType isEqualToString:UIActivityTypeMessage]){
NSString *string = label1.text;
if ([string length] > 140) {
return self.finalString;
}
else {
return label1.text;
}
}
return nil;
}

Resources