A motley medley of issues: Paypal, Threads, Navigation

Discussion in 'iOS Programming' started by Tiiba, Sep 14, 2010.

  1. Tiiba macrumors newbie

    Joined:
    Jul 9, 2010
    #1
    Paypal:

    I'm trying to get my Iphone program to make a payment. I created a sandbox account, and then followed the instructions here:

    https://www.x.com/community/ppx/xspaces/mobile/mep

    Here is what I wrote:

    PHP:
        [PayPal initializeWithAppID:@"APP-80W284485P519543T" forEnvironment:ENV_SANDBOX];
        
    PayPal *pp = [PayPal getInstance];
        
    PayPalMEPPayment *payment =[[PayPalMEPPayment allocinit];
        
        
    payment.paymentCurrency = @"USD";
        
    payment.paymentAmount = @"10.00";
        
    payment.itemDesc = @"[a string]";
        
    payment.recipient = @"[email of the sandbox business account]";
        
    payment.merchantName = @"We R Igors";
        [
    pp Checkout:payment];
        [
    payment release];
    }
    I ran the program and saw a popup asking for my login. I tried the email of the personal account, with the number substring as the password. I tried the info for the business account, because that's what was in "API credentials". I tried the developer site login. None of them work. I don't know what I'm supposed to enter. Or is the problem that I need to do something special, like signing the program? I don't think I need to yet, plus I don't know how.


    Threads:
    Another one, not related. If I need to put this in a new thread, inform me, I'm not sure. I have a table in a nav controller, and each row has a downloaded image. Images are downloaded asynchronously:

    PHP:
    [NSThread detachNewThreadSelector:@selector(doDownload:) toTarget:self withObject:urlAddr];
    Well, this worked great for a while. Then something changed, and while the threads do indeed detach, the screen stays black until everything is loaded. The root controller's constructor runs to the end, but the method that fills the rows doesn't get called until the end. This means that I made the program complicated and got no benefit. What could it be? Did I use locking wrong?

    Here's doDownload:

    PHP:
    -(void)doDownload:(NSString*)urlAddr
    {    
        
    NSAutoreleasePool pool = [[NSAutoreleasePool allocinit];
        
        @
    synchronized(self)
        {
            
    NSURLurl = [NSURL URLWithStringurlAddr];
            
    NSDatadata = [NSData dataWithContentsOfURLurl];
            [
    data retain];
            
    img = [UIImage imageWithData:data];
            
    imageView = [[UIImageView allocinitWithImage:img];
            [
    self addSubview:imageView];
            
    imageView.frame self.bounds;
            [
    imageView setNeedsLayout];
            [
    self setNeedsLayout];
            [
    imageView retain];
        }
        
        [
    pool release];
        
    BOOL a = [NSThread isMultiThreaded];
    }
    In the GUI, I use the nav controller to switch between several tables. If the row's image is already downloaded, I construct a new imageview. Else, I use the view ImageDownloader, from which the above code comes.

    GUI:

    Sometimes, when I back up the navigation controller, a text view in the cell I just clicked on seems to be overlapped with either another cell's corresponding view or with a dislocated copy of itself. I dutifully remove old copies from the "ReusableCellWithIdentifier". What do I need to do? Perhaps force the cell to repaint? How?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    You should make separate threads for each question.

    Your threads question is answered by telling you that UIKit is not thread safe, at least not most of it. You can't create a UIImageView or addSubview or anything like that in any thread but the main thread. Look at the LazyTableImages Apple sample code which shows how to do this.
     
  3. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #3
    The simple answer to your second question is: don't use threads for networking and don't use UIKit in a background thread as its not entirely thread safe.

    Use asynchronous APIs, NSOperation or GCD for your networking.

    The more elaborate answer is found in this dev forums link:
    https://devforums.apple.com/thread/9606?tstart=0
     

Share This Page