Open rmaddy opened 8 years ago
Thanks for this! I ran into the same exact issue, and couldn’t figure out what was going on!
I just incorporated your idea into my copy of this project so I can be alerted about these kinds of things in the future:
In ReportDownloadOperation.m
line 60:
NSMutableDictionary *errors = [[NSMutableDictionary alloc] init];
…and replaced line 177 in ReportDownloadOperation.m
with:
// The message "Daily Reports are only available for past 365 days. Please enter a new date."
// just means that the report in question has not yet been released.
// We can safely ignore this error and move on.
if ([errorMessage rangeOfString:@"past 365 days"].location == NSNotFound) {
NSLog(@"%@ -> %@", reportDateString, errorMessage);
NSInteger year = [[reportDateString substringWithRange:NSMakeRange(0, 4)] intValue];
NSInteger month = [[reportDateString substringWithRange:NSMakeRange(4, 2)] intValue];
NSInteger day = [[reportDateString substringWithRange:NSMakeRange(6, 2)] intValue];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:year];
[components setMonth:month];
[components setDay:day];
NSDate *reportDate = [[NSCalendar currentCalendar] dateFromComponents:components];
NSMutableDictionary *reportTypes = [[NSMutableDictionary alloc] initWithDictionary:errors[errorMessage]];
NSMutableArray *reports = [[NSMutableArray alloc] initWithArray:reportTypes[dateType]];
[reports addObject:reportDate];
reportTypes[dateType] = reports;
errors[errorMessage] = reportTypes;
}
…and right before line 225 in ReportDownloadOperation.m
:
dispatch_async(dispatch_get_main_queue(), ^{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterNoStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;
for (NSString *error in errors.allKeys) {
NSString *message = error;
NSDictionary *reportTypes = errors[error];
for (NSString *reportType in reportTypes.allKeys) {
message = [message stringByAppendingFormat:@"\n\n%@ Reports:", reportType];
for (NSDate *reportDate in reportTypes[reportType]) {
message = [message stringByAppendingFormat:@"\n%@", [dateFormatter stringFromDate:reportDate]];
}
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil)
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil];
[alertView show];
}
});
This code generates a summarized error alert for each distinct error message encountered:
I've been seeing the error The report could not be downloaded, please try again later.
but I don't think it's related to 2-factor auth.
Refreshing again seems to pull the report down.
Thanks for posting your solution to the problem. For those who might not be aware of the method of creating an app-specific password: https://support.apple.com/en-us/HT204397
I'm getting an error after daily report is downloaded. Maybe it's payment download issue?
Yes it's payments. I haven't had the time to look into it myself yet. iTunesConnect login page changed.
I’ve just added UI to handle two-step verification and proper app-specific password support to my fork of AppSales, and submitted a pull request to @ddaddy's fork (https://github.com/ddaddy/AppSales-Mobile/pull/1). Go check it out if you’re interested.
@nicolasgomollon does it fix payments download error?
BTW, is there any option in ITC to download payments manually to import them to App Sales?
@nicolasgomollon Thanks for your additions. I do apologise, I haven't had the time to take a look yet, but it is on my todo list.
@Morpheus2002 No it won't fix the payments, however that is also on my todo list to take a look at. There's no way to export/import payments as they are literally scraped from the web page.
@ddaddy thanks for your answer! I took a look at ITC, but couldn't find any fix for this issue.
The payment issue, will be down to the new login view for iTC.
@Morpheus2002 @ddaddy My fork of AppSales does indeed fix the Payments download issue (among other minor issues). I also added in some UI to handle Two-Step Verification code input, since developer accounts with this enabled are now required to verify their account on untrusted devices, so my fork supports these accounts as well.
The problem was initially due to the changed iTunes Connect login page.
The way I accomplished this was by performing the login via the Member Center (which has a much more simplified page structure, and is much less hacky), and then visiting the Payments and Financial Reports page in iTunes Connect. This works because both the Member Center and iTunes Connect use the same cookies to recognize a logged in user.
I’ve made so many other changes to my fork since fixing this, so you might have to dig in to my commit history to find the right commits, or you can download a copy of my fork and give it a try for yourself.
EDIT: Here are the highlight commits that address this issue:
@nicolasgomollon that's awesome, thanks. It just moved higher up my todo list.
@nicolasgomollon still getting same payments error (indicated parsing error of login page) on your latest commit
@pupasani Do you mind providing additional details about the error?
The page structure might be a bit different for accounts that only have one vendor ID (and mine happens to have two), which may be the cause of your issue. Could you provide a snippet of the source code of your Payments and Financial Reports page, specifically the part where the vendor ID is shown? (See example snippet below.)
<form name="mainForm" enctype="multipart/form-data" method="post" action="/WebObjects/iTunesConnect.woa/wo/25.0.0.11.5.0.9.3.1">
<table width="980" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="8"><img src="https://itc.mzstatic.com/itc/images/wrapper_topl.png" width="8" height="51" alt=""></td>
<td width="*" background="https://itc.mzstatic.com/itc/images/wrapper_top.png" height="51" align="center" class="header_text">
<div class="vendor-id-container">
<select onMouseDown="toggleVendorIdWidth()" style='top: 10px' onBlur="this.style.width = '250px'" onChange="this.form.submit();" class="vendor-id-select" id="vendor-id" name="0.0.11.5.0.9.3.1.5.1">
<option value="0">Vendor Name One - 8XXXXXXX</option>
<option selected="selected" value="1">Vendor Name Two - 8XXXXXXX</option>
</select>
</div>
<p id="header-txt">Payments and Financial Reports</p>
</td>
@nicolasgomollon I have cherry picked some of your changes for my branch thanks. I noticed on a couple of occasions during testing, if I deleted the payments from my 2 accounts, it would download the same batch of payments for both.
@nicolasgomollon my page does not have the vendor-id-container div at all. Here's the snippet:
After installing the latest version of this app and deleting sales reports from October 26 and later I tried to redownload those reports. The app appeared like it was downloading and processing the reports but in the end, there were no bars for those days.
Then I noticed a bunch of errors in the console about the fact that my account uses two-factor authentication and I should create an app-specific app id.
So I guess this is an enhancement request that could help anyone complaining that this app isn't downloading any new reports. The app didn't indicate there was any error during the download. It would be nice if this app could present any download errors instead of silently ignoring them. Such an error message would have saved me some head scratching trying to figure out why I wasn't getting any new reports.
BTW - in my case I created app-specific app id and updated the password in this app with the new password and it started working again.