Developer's Guide

8 August 2012 PayPal Mobile Payments Developer Guide and Reference – iOS Edition
NOTE: The Mobile Payments Library binds specific devices to specific application IDs, for
enhanced security. For each of your application IDs, you must use a different sandbox
account for each of your devices or simulators. To switch a device or simulator to use a
different sandbox account, go to the PayPal Sandbox website on your computer, select
Profile > Mobile Applications, and then unbind the device from the application ID.
You have two options for when to call the
initializeWithAppID method:
Initialize the PayPal object on the main thread, when you need it. Initialize the library
each time before you call the
getPayButtonWithTarget method. This implementation is
simple because it uses a single-threaded programming model. The
initializeWithAppID
call is blocking, so your application waits for the initialization to complete.
To use this method, you can use one line of code:
[PayPal initializeWithAppID:appID];
Or:
[PayPal initializeWithAppID:appID forEnvironment:env];
On subsequent lines you can then reference the PayPal object with
[PayPal
getInstance]
.
Initialize the PayPal object on a separate thread, when your application starts. Initialize
the library once. This implementation is complex because it uses a multiple-threaded
programming model. The
initializeWithAppId call is not blocking, so your main
application thread continues while the initialization completes in the background. This way
the button is ready to display when you need it.
The following sample code initializes the PayPal object on a separate thread.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:navController.view];
[window makeKeyAndVisible];
[NSThread detachNewThreadSelector:@selector(initializePayPal)
toTarget:self withObject:nil];
}
-(void)initializePayPal {
[PayPal initializeWithAppID:@"APP-80W284485P519543T"
forEnvironment:ENV_SANDBOX];
}
Inside the AppDelegate’s
applicationDidFinishLaunching method, the code starts the
initializeWithAppId method on a new thread.