1014Installing IIJmio Sim-Card on iPhone
Problem: IIJMIO Network not working:
Solution: Dowload and Install Profile
1. Go to https://t.iijmio.jp/en/apn/
2. Download and Install the Profile
3. That’s it.
for (NSString *familyName in [UIFont familyNames]) {
NSLog(@"%@, %@", familyName, [UIFont fontNamesForFamilyName:familyName]);
}
And here is the current result:
2010-05-17 17:38:05.931 fonts[20843:207] AppleGothic, ( AppleGothic ) 2010-05-17 17:38:05.932 fonts[20843:207] Hiragino Kaku Gothic ProN, ( "HiraKakuProN-W6", "HiraKakuProN-W3" ) 2010-05-17 17:38:05.932 fonts[20843:207] Arial Unicode MS, ( ArialUnicodeMS ) 2010-05-17 17:38:05.932 fonts[20843:207] Heiti K, ( "STHeitiK-Medium", "STHeitiK-Light" ) 2010-05-17 17:38:05.932 fonts[20843:207] DB LCD Temp, ( DBLCDTempBlack ) 2010-05-17 17:38:05.932 fonts[20843:207] Helvetica, ( "Helvetica-Oblique", "Helvetica-BoldOblique", Helvetica, "Helvetica-Bold" ) 2010-05-17 17:38:05.932 fonts[20843:207] Marker Felt, ( "MarkerFelt-Thin" ) 2010-05-17 17:38:05.933 fonts[20843:207] Times New Roman, ( TimesNewRomanPSMT, "TimesNewRomanPS-BoldMT", "TimesNewRomanPS-BoldItalicMT", "TimesNewRomanPS-ItalicMT" ) 2010-05-17 17:38:05.933 fonts[20843:207] Verdana, ( "Verdana-Bold", "Verdana-BoldItalic", Verdana, "Verdana-Italic" ) 2010-05-17 17:38:05.933 fonts[20843:207] Georgia, ( "Georgia-Bold", Georgia, "Georgia-BoldItalic", "Georgia-Italic" ) 2010-05-17 17:38:05.933 fonts[20843:207] Arial Rounded MT Bold, ( ArialRoundedMTBold ) 2010-05-17 17:38:05.933 fonts[20843:207] Trebuchet MS, ( "TrebuchetMS-Italic", TrebuchetMS, "Trebuchet-BoldItalic", "TrebuchetMS-Bold" ) 2010-05-17 17:38:05.933 fonts[20843:207] Heiti TC, ( "STHeitiTC-Light", "STHeitiTC-Medium" ) 2010-05-17 17:38:05.933 fonts[20843:207] Geeza Pro, ( "GeezaPro-Bold", GeezaPro ) 2010-05-17 17:38:05.934 fonts[20843:207] Courier, ( Courier, "Courier-BoldOblique", "Courier-Oblique", "Courier-Bold" ) 2010-05-17 17:38:05.934 fonts[20843:207] Arial, ( ArialMT, "Arial-BoldMT", "Arial-BoldItalicMT", "Arial-ItalicMT" ) 2010-05-17 17:38:05.934 fonts[20843:207] Heiti J, ( "STHeitiJ-Medium", "STHeitiJ-Light" ) 2010-05-17 17:38:05.934 fonts[20843:207] Arial Hebrew, ( ArialHebrew, "ArialHebrew-Bold" ) 2010-05-17 17:38:05.934 fonts[20843:207] Courier New, ( "CourierNewPS-BoldMT", "CourierNewPS-ItalicMT", "CourierNewPS-BoldItalicMT", CourierNewPSMT ) 2010-05-17 17:38:05.934 fonts[20843:207] Zapfino, ( Zapfino ) 2010-05-17 17:38:05.934 fonts[20843:207] American Typewriter, ( AmericanTypewriter, "AmericanTypewriter-Bold" ) 2010-05-17 17:38:05.935 fonts[20843:207] Heiti SC, ( "STHeitiSC-Medium", "STHeitiSC-Light" ) 2010-05-17 17:38:05.935 fonts[20843:207] Helvetica Neue, ( HelveticaNeue, "HelveticaNeue-Bold" ) 2010-05-17 17:38:05.935 fonts[20843:207] Thonburi, ( "Thonburi-Bold", Thonburi )
Header Search Paths
, which can become troublesome when working with SVN’ed projects.
And because the architecture differs on the iPhone (ARM) and the Simulator (i386), having precompiled libraries is not the best solution. But adding a depended library project to your projects kind of negates the advantages of having reusable code by adding unnecessary complications.
Recommendation? Just add the desired files to your project. And if you really mind, don’t copy, but only include by reference.
#include ;
// Gives you TARGET_IPHONE_SIMULATOR and TARGET_OS_IPHONE target conditionals.
// Set hello to "Hello, "!
#if TARGET_IPHONE_SIMULATOR
NSString *hello = @"Hello, iPhone Simulator!";
#else
NSString *hello = @"Hello, iPhone device!";
#endif
//Determining whether you’re compiling for the iPhone OS
#if TARGET_OS_IPHONE
#import
#else
#import
#endif
Conditionalizing Compilation and Linking from the Apple Dev Library.
I came across a simple and short IPHONE target conditional at some framework, but that did not seemed to do the trick. I am probably missing something there.
–
Update 1.
tconf might be a step into the right directions.
Just out of curiosity, here a incomplete list of available target conditionals:
TARGET_IPHONE_SIMULATOR
TARGET_CARBON
TARGET_OS_IPHONE
TARGET_CPU_PPC
TARGET_CPU_PPC64
TARGET_CPU_68K
TARGET_API_MAC_OSX
PRAGMA_ALIGN_SUPPORTED
TARGET_OS_UNIX
TARGET_OS_EMBEDDED
TARGET_OS_MAC
TARGET_OS_WIN32
TARGET_OS_UNIX
TARGET_OS_EMBEDDED
TARGET_RT_MAC_CFM
TARGET_RT_MAC_MACHO
...
Update 2.
And that’s the motherload. Nice of Apple to open-source that.
Portrait (top home button)
Portrait (bottom home button)
Landscape (left home button)
Landscape (right home button)
192.168.20.117/live.jpg
Viewing it in a browser an refreshing it should give you updated images. So far so good. (Of course, the address is my local address, yours might vary.)
Now, basically all we have to do is to make a simple iPhone Appli, ask it to reload the image periodically and display the image.
– create a NSURLConnection and point it to the image address
– collect the data, and display it once the download is completed
– download the image again after 40ms.
What can I see, I am surprised it works quite well. Clearly there are some troubles: about 1% of the returned images feature not data, which would result in a flicker on the iPhone… A simple test, whether the received [data length] > 0 takes care of that problem.
I am guessing, that this is caused by a collision of the write time of the max patch and the download time of the iPhone application, but I am not 100% sure. If anyone knows the answer, let me know.
And, yeah, I should really make a videp demo-ing that…
Anywhere, here are the juicy bits of the code:
- (void)loadView {
[super loadView];
NSLog(@"start");
reloadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480, 320)];
reloadImageView.center = CGPointMake(160.0, 240.0);
reloadImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:reloadImageView];
self.view.backgroundColor = [UIColor blueColor];
[reloadImageView release];
struct timeval tv;
gettimeofday(&tv, NULL);
diff = tv.tv_sec;
[self downloadImage];
}
- (void)downloadImage {
startTimestamp = [self currentTime];
NSString *address = @"http://192.168.20.117/live.jpg";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:address]];
[NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
downloadErrors++;
[self downloadImage];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//NSLog(@"didReceiveResponse");
data = nil; // clear
[data release]; // release
data = [[NSMutableData alloc] initWithCapacity:20000]; // create & retain
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)partialData {
//NSLog(@"didReceiveData");
[data appendData: partialData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//NSLog(@"connectionDidFinishLoading");
float difference = (([self currentTime] - startTimestamp) - 0.040);
if ([data length] > 0) {
// check if data has content (displaying an empty data
// images shows nothing, but flashes the background)
reloadImageView.image = [UIImage imageWithData:data];
imagesDownloaded++;
totalBytes += [data length];
} else {
zeroBytes++;
}
if (difference < 0) {
[self performSelector:@selector(downloadImage) withObject:nil afterDelay:fabs(difference)];
} else {
[self downloadImage]; // loop
}
}
- (float)currentTime {
struct timeval tv;
gettimeofday(&tv, NULL);
float msec = tv.tv_usec / 1000000.0;
float current = (tv.tv_sec - diff) + msec;
return current;
}
And here is the whole demo Xcode project. Make sure to change the image address to your local image. I also include a simple Max-patch, that saves images from a camera to disk.
Update
Although the initial diff timer was in the sniplet here, it did not make it in the original Xcode project. Mistake corrected, now the Xcode project should reflect the code here.
“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.” The following non-public API is included in your application: singleTap:Hmm. Clearly I did not use a private API, apparently I just happened to call a function the same name as a private API function… Wondering if there is a list of reserved function names, which is triggered a rejection? Solution? I commented out the superflicial notification AND renamed the function to ‘oneTap’. Just in case. I am starting to believe the stories about the Apple store.
//
// UIApplication-Network.h
//
// SystemConfiguration.framework will need to be added to your project
//
// To use just call as a class function [UIApplication hasNetworkConnection]
//
#import
#import
@interface UIApplication (NetworkExtensions)
+(BOOL)hasActiveWiFiConnection; // fast wi-fi connection
+(BOOL)hasNetworkConnection; // any type of internet connection (edge, 3g, wi-fi)
@end
UIApplication-Network.m
//
// UIApplication-Network.m
//
#import "UIApplication-Network.h"
@implementation UIApplication (NetworkExtensions)
#define ReachableViaWiFiNetwork 2
#define ReachableDirectWWAN (1 << 18)
// fast wi-fi connection
+(BOOL)hasActiveWiFiConnection
{
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityRef reachabilityRef;
BOOL gotFlags;
reachabilityRef = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.apple.com" UTF8String]);
gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
CFRelease(reachabilityRef);
if (!gotFlags)
{
return NO;
}
if( flags & ReachableDirectWWAN )
{
return NO;
}
if( flags & ReachableViaWiFiNetwork )
{
return YES;
}
return NO;
}
// any type of internet connection (edge, 3g, wi-fi)
+(BOOL)hasNetworkConnection;
{
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityRef reachabilityRef;
BOOL gotFlags;
reachabilityRef = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.apple.com" UTF8String]);
gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
CFRelease(reachabilityRef);
if (!gotFlags || (flags == 0) )
{
return NO;
}
return YES;
}
@end
Also, don't forget to add the SystemConfiguration.framework to the Frameworks folder in your application.
In case you get errors like that:
"_SCNetworkReachabilityGetFlags", referenced from:
+[UIApplication(NetworkExtensions) hasActiveWiFiConnection] in UIApplication-Network.o
+[UIApplication(NetworkExtensions) hasNetworkConnection] in UIApplication-Network.o
"_SCNetworkReachabilityCreateWithName", referenced from:
+[UIApplication(NetworkExtensions) hasActiveWiFiConnection] in UIApplication-Network.o
+[UIApplication(NetworkExtensions) hasNetworkConnection] in UIApplication-Network.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build failed (2 errors)