Page 3 of 15 FirstFirst 12345678910111213 ... LastLast
Results 21 to 30 of 144
Discuss [XCode Template] for SDK and Open Toolchain API in firmware 2.0 at the iPhone Developer Exchange - Hackint0sh.org; I have been asked whether the UIAccelerometer code of HelloSensor.app ( post 13 ) can ...
  1. #21
    Developer Array javacom's Avatar

    Join Date
    Mar 2008
    Posts
    304
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    28

    Default HelloSensor.app for SDK API

    I have been asked whether the UIAccelerometer code of HelloSensor.app (post 13) can be run on SDK API or not ?

    So here this is the modified version (with 3 files below) for the iPhone SDK API. And I have tested this on the SDK beta 3.

    The original version that run in firmware 1.x with open toolchain API is from Erica Sadun.

    Code:
    //
    //  main.m
    //  SensorSDK3
    //
    #import <UIKit/UIKit.h>
    
    int main(int argc, char *argv[])
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, nil, @"SensorSDK3AppDelegate");
        [pool release];
        return retVal;
    }
    Code:
    //
    //  SensorSDK3AppDelegate.h
    //  SensorSDK3
    //
    
    #import <UIKit/UIKit.h>
    #include <stdio.h>
    #include <time.h>
    #include <math.h>
    
    #define kUpdateFrequency 10  // Hz
    
    
    @interface SensorSDK3AppDelegate : NSObject <UIAccelerometerDelegate> {
        UIWindow	*window;
    	UITextView   *textView;
    	UIImageView  *xarrow;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) UITextView *textView;
    @property (nonatomic, retain) UIImageView  *xarrow;
    
    - (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz;
    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
    @end
    Code:
    //
    //  SensorSDK3AppDelegate.m
    //  SensorSDK3
    //
    
    #import "SensorSDK3AppDelegate.h"
    
    UIImage *createImageWithText(CGSize imageSize, NSString *text);
    
    @implementation SensorSDK3AppDelegate
    
    @synthesize window;
    @synthesize textView;
    @synthesize xarrow;
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {	
    
    	self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
    
    	self.textView = [[UITextView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
    	self.textView.font = [UIFont systemFontOfSize:24];
        self.textView.editable = NO;
        self.textView.textAlignment = UITextAlignmentLeft;
    
    	UIImage *img = createImageWithText(CGSizeMake(85,40),@"-->");
    	self.xarrow = [[UIImageView alloc] initWithImage:img];
    	self.xarrow.center=self.textView.center;
        self.xarrow.clearsContextBeforeDrawing = NO;
    
    	
        [textView addSubview:xarrow];
    
    	// Show window
    	[window addSubview:textView];
    	[window makeKeyAndVisible];
    
    	[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(20.0 / kUpdateFrequency)];
    	[[UIAccelerometer sharedAccelerometer] setDelegate:self];
    
    }
    
    /*
    The meaning of X, Y, Z by Erica Sadun (with modification for the range from -1.0 to 1.0 for firmware 2.0)
    X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece. 
        Values vary from 1.0 (rolled all the way to the left) to -1.0 (rolled all the way to the right).
    
    Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen. 
        That's the axis around which the Y value rotates. 
    	Values go from 1.0 (the headphone jack straight down) to -1.0 (the headphone jack straight up).
    
    Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not. 
        It refers to whether your iPhone is face up (-1.0) or face down (1.0). 
    	When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite
    	, the Z value equates to 0.0.
    */
    
    - (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz
    {
    
       // Create Status feedback string
       NSString *xstring = [NSString stringWithFormat:
          @"X (roll, %4.1f%%): %f\nY (pitch %4.1f%%): %f\nZ (%4.1f%%) : %f",
          100.0 - (xx + 1.0) * 100.0, xx, 
          100.0 - (yy + 1.0) * 100.0, yy, 
          100.0 - (zz + 1.0) * 100.0, zz
    	  ];
    	  self.textView.text = xstring;
    
       // Revert Arrow and then rotate to new coords
       float angle = atan2(xx, yy);
       angle += M_PI / 2.0;
    
    	CGAffineTransform affineTransform = CGAffineTransformIdentity;
    	affineTransform = CGAffineTransformConcat( affineTransform, CGAffineTransformMakeRotation(angle));
    	self.xarrow.transform = affineTransform;
    
    }
    
    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    	[self acceleratedInX:acceleration.x Y:acceleration.y Z:acceleration.z];
    }
    
    
    - (void)dealloc {
    	[textView release];
    	[xarrow release];
    	[window release];
    	[super dealloc];
    }
    
    @end
    
    // Returns an image of the given size containing the given string
    UIImage *createImageWithText(CGSize imageSize, NSString *text) {
    	
    	// Create a bitmap graphics context of the given size
    	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    	CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, imageSize.width*4, colorSpace, kCGImageAlphaPremultipliedLast);
    	CGColorSpaceRelease(colorSpace);
    	if (context== NULL) {
     		return nil;
    	}
    		
    	// Custom CGContext coordinate system is flipped with respect to UIView, so transform, then push
    	CGContextTranslateCTM(context, 0, imageSize.height);
    	CGContextScaleCTM(context, 1.0, -1.0);
    	UIGraphicsPushContext(context);
    
    	// Inset the text rect then draw the text
    	CGRect textRect = CGRectMake(4, 2, imageSize.width - 8, imageSize.height - 8);
    	UIFont *font = [UIFont boldSystemFontOfSize:24];
    	[[UIColor blackColor] set];
    	[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
    	
    	// Create and return the UIImage object
    	CGImageRef cgImage = CGBitmapContextCreateImage(context);	
    	UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];
    	UIGraphicsPopContext();
    	CGContextRelease(context);
    	CGImageRelease(cgImage);
    	return uiImage;
    }


  2. #22
    Developer Array javacom's Avatar

    Join Date
    Mar 2008
    Posts
    304
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    28

    Default Interface Builder for Open Toolchain Template

    Interface Builder for Open Toolchain Template

    Some of sample applications from SDK have used Interface Builder file (*.xib) in the project. In order to use the IB file, the local UIKit.h header is enhanced and a new Xcode template is created. It is called "Window-Based Toolchain" and is added to the first post Xcode template of this thread. The MainWindow.xib of this template has only one window as IBOutlet.

    I have tested this new Window-Based Toolchain template to build the SimpleTableViewApp of SDK3 and in order to build under open toolchain header, the sample code of this app should be amended as below

    Code:
    #ifdef ASPEN
    #import "UIKit.h"
    #import "SimpleTableViewAppDelegate.h"
    #else
    #import <UIKit/UIKit.h>
    #endif
    
    int main(int argc, char *argv[])
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    #ifdef ASPEN
    	int retVal = UIApplicationMain(argc, argv, [SimpleTableViewAppDelegate class]);
    #else
        int retVal = UIApplicationMain(argc, argv, nil, @"SimpleTableViewAppDelegate");
    #endif
        [pool release];
        return retVal;
    }
    Code:
    /*
    File: SimpleTableViewAppDelegate.h
    */
    
    #ifdef ASPEN
    #import "UIKit.h"
    #else
    #import <UIKit/UIKit.h>
    #endif
    #import "RootViewController.h"
    
    #ifdef ASPEN
    @interface SimpleTableViewAppDelegate : UIApplication <UITextFieldDelegate, UISearchBarDelegate>
    #else
    @interface SimpleTableViewAppDelegate : NSObject <UIApplicationDelegate,UITextFieldDelegate, UISearchBarDelegate>
    #endif
    {
    	
    	IBOutlet UIWindow *window;
    	UINavigationController *navigationController;
    	
    	NSMutableArray *list;
    }
    Code:
    /*
    File: RootViewController.h
    */
    #ifdef ASPEN
    #import "UIKit.h"
    #else
    #import <UIKit/UIKit.h>
    #endif
    For this sample app, it is possible to add the UISearchBar in this and this works very well. Please refer to here for the required code amendment.

    There is also a Makefile in the xcode template, so that you can compile the xib to nib file and package it and manual install to /Applications folder of iPhone by scp, in addition to "build and go" in Xcode environment.

    To get the updated version "UIKit.h" and Makefile, you can install the version 2.1 of the Xcode Template
    Please refer to the first post on how to install this Xcode Template

    This Xcode template has been tested on pwned iPhone (build 5a240d) and iPhone SDK beta 3

    Last edited by javacom; 06-19-2008 at 04:29 PM.

  3. #23
    Senior Professional Array

    Join Date
    Mar 2007
    Posts
    147
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    It appears Itunes 7.7 breaks the ability to deploy to a beta 3 iphone. Xcode reports the error "No provisioned iPhone OS device is connected." The Organizer won't detect it either.

  4. #24
    Developer Array javacom's Avatar

    Join Date
    Mar 2008
    Posts
    304
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    28

    Default

    It is very likely that the dev team will update the toolchain and gcc compiler after jailbreak the firmware 2.0, as you can see there are Cydia, Installer, BootNeuter in their jailbroken iPhone.

    If iTunes 7.7 breaks the deployment, we might need to wait for the update from dev team.

  5. #25
    Newbie Array

    Join Date
    Jan 2008
    Posts
    3
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    Hi javacom,

    Nice stuff, works good.

    I have one question.

    When there will be jailbreak for official 2.0, how will i compile apps i compiled for beta 3 using your method?

    Will it work? you use toolchain headers in this special way. will it be possible to compile using those headers for official 2.0?
    I'm just afraid i'll have to change all my code in the end just to compile for official 2.0...


  6. #26
    Developer Array javacom's Avatar

    Join Date
    Mar 2008
    Posts
    304
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    28

    Default

    Quote Originally Posted by Kingstone View Post
    Hi javacom,

    Nice stuff, works good.

    I have one question.

    When there will be jailbreak for official 2.0, how will i compile apps i compiled for beta 3 using your method?

    Will it work? you use toolchain headers in this special way. will it be possible to compile using those headers for official 2.0?
    I'm just afraid i'll have to change all my code in the end just to compile for official 2.0...
    I think most of us want to have one source code compiled for both open toolchain header and official sdk header. At present, I only use conditional compiler directive #ifdef #else #endif. But it is only for UIKit headers only.

    We will have to wait for the upgrade of the open toolchain headers to see what can be done. The dev team is the expert on this.

  7. #27
    Newbie Array

    Join Date
    Apr 2008
    Posts
    3
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default debugging code

    I'm trying to compile an app using the open toolchain.

    I've found that you need to use erica sadun's utility "launch" to run the program

    going into the Applications/yourApp.app directory and running
    ./yourApp doesn't work any more.

    I've got NSLog statements in my code but when I ssh into the iphone and "launch" the program I don't see the messages displayed.

    I'm trying to debug my code as I go..

    Have others experienced this?

    thanks

  8. #28
    Newbie Array

    Join Date
    Jan 2008
    Posts
    3
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    I'm trying to port a 1.1.4 application i've made to 2.0 using your xcode patch/template.
    Well I got it to compile but when I run it, it gets stuck in UIApplicationMain...
    It never reaches appDidFinishLaunching method in my app controller class...
    I'm not sure but could it be because i use .mm for my app controller class? (i use c++ code and other external classes)
    It's weird the whole program compiled fine...

  9. #29
    Developer Array javacom's Avatar

    Join Date
    Mar 2008
    Posts
    304
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    28

    Default

    I do not code c++ / objective c++, so I have nothing to comment on this.

    But I think we all need to wait for pwnage tools and the upgrade of toolchain from the dev team in order to port app to firmware 2.0 (not beta)

  10. #30
    Senior Professional Array

    Join Date
    Mar 2007
    Posts
    147
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    Any chance of an update to the template for the final sdk? Also please could you add in IOKit framework support? It has the extremely necessary power management functions.

    Thanks.


 

 

LinkBacks (?)

  1. 02-16-2009, 06:37 AM
  2. 01-28-2009, 07:22 AM

Similar Threads

  1. MacNN: Apple working on official magazine template for Xcode?
    By hackint0sh in forum Latest Headlines
    Replies: 0
    Last Post: 03-14-2011, 03:10 PM
  2. [Xcode Problems] About Open Toolchain dev in Xcode
    By satashi in forum iPhone Developer Exchange
    Replies: 2
    Last Post: 02-08-2011, 11:26 AM
  3. Xcode Open Toolchain Application link error?
    By syamooo in forum iPhone Developer Exchange
    Replies: 1
    Last Post: 09-28-2010, 06:59 AM
  4. Development and distribution questions Xcode + template
    By antzee in forum iPhone Developer Exchange
    Replies: 1
    Last Post: 07-07-2009, 09:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin®
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO
(c) 2006-2012 Hackint0sh.org
All times are GMT +2. The time now is 10:22 AM.
twitter, follow us!