Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Download PhoneGap 1.7 and install the iOS plugin.
     
  2. Download Xtify iOS SDK v2.x.
     
  3. Create your Apple provisioning profile and generate your Xtify AppKey.
     
  4. Create a new xCode project, select PhoneGap based application and uncheck automatic reference counting. We suggest getting started by following the PhoneGap start page for instructions on how to build your first PhoneGap app.
     
  5. Unzip the Xtify SDK and drag and drop the Xtify library (XtifyLib) folder only into the sample app, check the box to “Copy items into destinations group’s folder (if needed), select “Create groups for any added folders”.
     
  6. Click on your project name in the left navigation pane, select your target application, then select Build Phases, Link Binary with Libraries, and click “+” to add any frameworks missing from the following list:
    1. Foundation.framework
    2. UIKit.framework
    3. CoreGraphics.framework
    4. SystemConfiguration.framework
    5. MapKit.framework
    6. CoreData.framework
    7. MessageUI.framework
    8. CoreLocation.framework
    9. CFNetwork.framework
    10. libxml2.2.dylib
    11. libz.1.1.3.dylib
    12. MobileCoreServices.framework
    13. CoreTelephony.framework
       
  7. Edit XtifyGlobal.h in the XtifyLib folder and enter your AppKey.
     
  8. Edit your app delegate files to include Xtify methods. Here is an example based on the sample PhoneGap app.

    Code Block
    titleAppDelegate.h
    #import <UIKit/UIKit.h>
    #ifdef CORDOVA_FRAMEWORK
        #import <Cordova/CDVViewController.h>
    #else
        #import "CDVViewController.h"
    #endif
    
    @class XLappMgr; // Xtify Application Manager-include it in your app 
    
    @interface AppDelegate : NSObject < UIApplicationDelegate, UIWebViewDelegate, CDVCommandDelegate > {
        NSString* invokeString;
        NSDictionary *launchNotification;
    }
    - (void) redirectConsoleLogToDocumentFolder;
    // invoke string is passed to your app on launch, this is only valid if you 
    // edit testxtifycordova-Info.plist to add a protocol
    // a simple tutorial can be found here : 
    // http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    
    @property (nonatomic, retain) IBOutlet UIWindow* window;
    @property (nonatomic, retain) IBOutlet CDVViewController* viewController;
    @property (copy)  NSString* invokeString;
    @property (nonatomic, retain) NSDictionary *launchNotification;
    
    @end
    Code Block
    AppDelegate.m
    #import "AppDelegate.h"
    #import "MainViewController.h"
    #ifdef CORDOVA_FRAMEWORK
        #import <Cordova/CDVPlugin.h>
        #import <Cordova/CDVURLProtocol.h>
    #else
        #import "CDVPlugin.h"
        #import "CDVURLProtocol.h"
    #endif
    #import "XLappMgr.h"
     
    @implementation AppDelegate
    @synthesize window, viewController, invokeString, launchNotification;
    - (id) init
    {   
        /** If you need to do any extra app-specific initialization, you can do it here
         *  -jm
         **/
        NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
        [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
             
        [CDVURLProtocol registerURLProtocol];
         
        if (self = [super init]) {
           XLXtifyOptions *anXtifyOptions=[XLXtifyOptions getXtifyOptions];
           [[XLappMgr get] initilizeXoptions:anXtifyOptions]; 
        }
        return self;
        // return [super init];
    }
    - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken 
    {
        NSLog(@"Succeeded registering for push notifications. Device token: %@", devToken);
        [[XLappMgr get] registerWithXtify:devToken ];
    }
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)pushMessage
    {
        NSLog(@"Receiving notification");
        [[XLappMgr get] appReceiveNotification:pushMessage];
    }
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        NSLog(@"Application is about to Enter Background");
        [[XLappMgr get] appEnterBackground];
    }
    - (void)applicationDidBecomeActive:(UIApplication *)application 
    {
        NSLog(@"Application moved from inactive to Active state");
        [[XLappMgr get] appEnterActive];
    }
    - (void)applicationWillEnterForeground:(UIApplication *)application 
    {
        NSLog(@"Application moved to Foreground");
        [[XLappMgr get] appEnterForeground];
    }
    -(void)applicationWillTerminate:(UIApplication *)application
    {
        NSLog(@"applicationWillTerminate");
        [[XLappMgr get] applicationWillTerminate];
    }
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error 
    {
        NSLog(@"Failed to register with error: %@", error);
        [[XLappMgr get] registerWithXtify:nil ];
    }
    #pragma UIApplicationDelegate implementation
    /**
     * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
     */
    - (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    {    
        NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
        NSString* invokeStringinvokedString = nil;
         
        if (url && [url isKindOfClass:[NSURL class]]) {
            invokeStringinvokedString = [url absoluteString];
            NSLog(@"FLD launchOptions = %@", url);
        }    
         
        CGRect screenBounds = [[UIScreen mainScreen] bounds];
        self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
        self.window.autoresizesSubviews = YES;
         
        CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
         
        self.viewController = [[[MainViewController alloc] init] autorelease];
        self.viewController.useSplashScreen = YES;
        self.viewController.wwwFolderName = @"www";
        self.viewController.startPage = @"index.html";
        self.viewController.invokeString = invokeStringinvokedString;
        self.viewController.view.frame = viewBounds;
         
        // check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
        BOOL forceStartupRotation = YES;
        UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
         
        if (UIDeviceOrientationUnknown == curDevOrientation) {
            // UIDevice isn't firing orientation notifications yet… go look at the status bar
            curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
        }
         
        if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
            for (NSNumber *orient in self.viewController.supportedOrientations) {
                if ([orient intValue] == curDevOrientation) {
                    forceStartupRotation = NO;
                    break;
                }
            }
        } 
         
        if (forceStartupRotation) {
            NSLog(@"supportedOrientations: %@", self.viewController.supportedOrientations);
            // The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
            UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0] intValue];
            NSLog(@"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
            [[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
        }
         
        [self.window addSubview:self.viewController.view];
        [self.window makeKeyAndVisible];
         
        [appMgr[XLAppMgr get] launchWithOptions:application andOptions:launchOptions];
         
        return YES;
    }
    // this happens while we are running ( in the background, or from within our own app )
    // only valid if FLD-Info.plist specifies a protocol to handle
    - (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url 
    {
        if (!url) { 
            return NO; 
        }
         
        // calls into javascript global function 'handleOpenURL'
        NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
        [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
         
        // all plugins will get the notification, and their handlers will be called 
        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
         
        return YES;    
    }
    - (void) dealloc
    {
        [super dealloc];
    }
    @end
  9. When you're ready to build, make sure you're using the Apple LVVM Compiler 3.x.

...