Wednesday, July 13, 2011

programmatically determine app is running in the iphone simulator?


NSString *model= [[UIDevice currentDevice] model];
NSString *iPhoneSimulator = @”iPhone Simulator”;
if ([model compare:iPhoneSimulator] == NSOrderedSame){
//device is simulator
}

CryptographicException APNS

[CryptographicException: An internal error occurred.
]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
   System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
   System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) +203
   System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password) +80
   System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) +79
   JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File, String p12FilePassword) +224
   JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32 value) +119
   JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean sandbox, String p12File, String p12FilePassword, Int32 connections) +211
   APN.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\iPhone\APN.aspx.cs:51
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
----
use code in NotificationConnection.cs: 

//certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword);
certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

Friday, July 8, 2011

FBConnect using other ViewController



in the YourApp_AppDelegate.h
#import "FBConnect.h"
Facebook *facebook;
@property (nonatomic, retain) Facebook *facebook;
In the YourApp_AppDelegate.m
@synthesize facebook;
Then in your application didFinishLaunchingWithOptions: function:
facebook = [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_API"];
From your viewController.h (any of them),
#import "YourApp_AppDelegate.h"
YourApp_AppDelegate *appDelegate;
And then, in your viewController.m viewDidLoad function:
appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];
Now, anytime you want to refer to your Facebook singleton, just refer to it like:
[appDelegate.facebook authorize:nil delegate:self];