PDA

View Full Version : ShareKit Email not working on multiple views




newtoiphonesdk
Apr 20, 2011, 02:59 AM
I have an app where one feature is the user can view current newsletter, article etc that are stored on website, and viewed using uiwebview. I have the following code setup with sharekit so the user can email people with whichever document is displayed as an attachment.
- (IBAction) share
{ NSString *urlString = @"http://www.maulroad.com/OnetoGrowon.doc";

NSURL *url = [NSURL URLWithString:urlString];

NSData *file = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"OnetoGrowon.doc"];

[file writeToFile:pdfPath atomically:YES];


SHKItem *item = [SHKItem file:file filename:@"OnetoGrowon.doc" mimeType:@"application/doc" title:@"One to Grow On By Johnny Hobbie"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[actionSheet showInView:self.view];

}
The problem is that I have this on 3 different views, corresponding to 3 different documents. I can email any one of them just fine, and it works perfectly, but if I go to a 2nd one and click the action button and then email, nothing pops up. Is the mail composer not dealloc properly? I have the SHKActionSheet dealloc in each of the void dealloc of each view, but it still won't let me send a 2nd email after successfully sending the first. Any thoughts?



newtoiphonesdk
Apr 21, 2011, 12:30 AM
The problem seems to be an intermittent one. Sometimes it will let me compose multiple emails in the app, sometimes only the first one will pull up the mailcomposeviewcontroller.

Sykte
Apr 21, 2011, 06:43 AM
The problem seems to be an intermittent one. Sometimes it will let me compose multiple emails in the app, sometimes only the first one will pull up the mailcomposeviewcontroller.

What's the delegate call back look like.

newtoiphonesdk
Apr 21, 2011, 10:04 AM
I have an app with 3 views that share a file via email. Each of them will work fine, if they are the first one to be sent. After one is sent, the mail composer will not pull up when I click email. They all use the same code (minus changes of the file to be sent) and is listed below.
#import "TenthView.h"
#import "SHK.h"

@implementation TenthView
@synthesize activity;
- (IBAction) share {


[activity startAnimating];
[self performSelector: @selector(share1) withObject: self afterDelay: 0];




}
- (void) share1
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSString *urlString = @"http://www.maulroad.com/Newsletter.pdf";

NSURL *url = [NSURL URLWithString:urlString];

NSData *file = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"Newsletter.pdf"];

[file writeToFile:pdfPath atomically:YES];


[self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:YES];

[pool release];


}
- (void) updateUI{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSString *urlString = @"http://www.maulroad.com/Newsletter.pdf";

NSURL *url = [NSURL URLWithString:urlString];

NSData *file = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"Newsletter.pdf"];

[file writeToFile:pdfPath atomically:YES];


SHKItem *item = [SHKItem file:file filename:@"Newsletter.pdf" mimeType:@"application/pdf" title:@"Maul Road Church of Christ Newsletter"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[actionSheet showInView:self.view];


[activity stopAnimating];
}
- (IBAction)done {
[self.parentViewController dismissModalViewControllerAnimated:YES];


}
- (void)awakeFromNib
{
[newsletter loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.maulroad.com/Newsletter.pdf"]]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];

}

-(void)tick {
if(!newsletter.loading)
[activity stopAnimating];
else
[activity startAnimating];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
// The device is an iPad running iPhone 3.2 or later.
return YES;
}
else
{
// The device is an iPhone or iPod touch.
return YES;
}

#else

// iPhone simulator
return NO;

#endif
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {

[super dealloc];
}


@end

xStep
Apr 21, 2011, 08:00 PM
Besides the fact that you repeated code you already did in a calling method, and that you seem to be using what looks like an unnecessary autorelease pool, the thing that jumps out in this sample is that you are writing to a non-unique file name. I've hi-lited it, alot. If the name is the same from one view to another, then you are trying to overwrite what may have existed before. I suppose there could be a timing issue here; you write the first version, while the SHKItem is still active you try to create a second file causing your weirdness of it occasionally working. ;)

Also, I know that some write methods don't allow overwriting an existing file. The docs don't say that for this NSData method, so that shouldn't be the problem.

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString *urlString = @"http://www.maulroad.com/Newsletter.pdf";
NSURL *url = [NSURL URLWithString:urlString];
NSData *file = [NSData dataWithContentsOfURL:url];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"Newsletter.pdf"];
[file writeToFile:pdfPath atomically:YES];

newtoiphonesdk
Apr 21, 2011, 08:49 PM
I got rid of the repeat code and pool code. The names of the files are different in each view. One is newsletter.PDF one is article.doc and one is announcements.PDF.