I am getting stream on iPad from an IP camera named Foscam. If I open IP in iPad browser then it is working good but when I fetch stream in my application then it gets on frist screen shot and stuck on it. App is not getting continuous streaming from cam. I am using this way
- (IBAction)powerChanged:(id)sender {
UISwitch * s = (UISwitch *)sender;
if( s.on == TRUE){
[self initializeData];
if(![deviceClient connect]){
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Can not connect to T-Rex device!"
message:[[NSString alloc] initWithFormat:#"Could not connec to %# and %d port",deviceClient.host,deviceClient.port]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
[s setOn:FALSE animated:TRUE];
} else {
[self adjustLayout:TRUE];
[self startFrequencyTimer];
}
}else {
[self stopFrequencyTimer];
[self adjustLayout:FALSE];
}
}
-(void)initializeData {
[cameraViewFront loadRequest:[NSURLRequest requestWithURL:[frontCameraClient getVideoStreamURL]]];
}
-(BOOL)connect {
if (udpSocket == nil){
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
NSLog(#"host %# and port %i", self.host, self.port);
return [udpSocket connectToHost:self.host onPort:self.port error:nil];
}
- (NSURL *) getURL:(NSString *)forPage {
NSLog(#"front cam IP %#" ,self.host);
return [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"http://%#/%#user=%#&pwd=%#",self.host,forPage,self.username, self.password]];
}
-(NSURL *)getVideoStreamURL{
return [self getURL:#"videostream.cgi?"];
}
I figured it out. I am using foscam and foscam provides a list of URLs on this link so I searched my cam model and then tried all the given URLs for MPEG connection type and http://IPADDRESS/videostream.cgi?user=[USERNAME]&pwd=[PASSWORD]&resolution=32&rate=0 URL worked for my case. But still there is a problem that it is working awesome on iOS5 and on iOS6 it still stuck on first frame.
To fix this problem this link helped me a lot. This method works for iOS5 and 6 both.
Related
I created messaging application like whatsApp and hike. Its working on 3G,4G and Wifi network. when user switch to 2G network my app connection is interrupted but whatsApp and hike working perfectly. I posting code where i manage app connection ::
#pragma mark - connect to the server
- (BOOL)connect {
if (!self.xmppStream) {
[self setupStream];
}
NSString *jabberID = [[NSUserDefaults standardUserDefaults] stringForKey:kUserName];
if (![self.xmppStream isDisconnected]) {
return YES;
}
if (jabberID == nil || kXMPPPassword == nil) {
return NO;
}
[self.xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
[self.xmppStream setHostName:kXMPPHost];
NSError *error = nil;
if (![self.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
// [alertView show];
NSLog(#"errorerrorerrorerrorerrorerror :- %#", error);
return NO;
}
return YES;}
- (void)connectThenSignIn {
if ([_xmppStream isConnecting]) { // Connection error, connection is being established
return ;
}
if ([_xmppStream isDisconnected]) { // If disconnected, a server connection is established
[self connect];
_goToRegisterAfterConnected = NO;
} else if ([_xmppStream isConnected]) {
[self doSignIn];
} }
Please suggest me best way to manage openfire connection on every network (2G, 3G, 4G and wifi).
Those applications are probably using push notifications to receive updates while on unreliable IP networks (like 2G). This allows them to appear online without maintaining a constant connection to a server.
This is difficult to accomplish with XMPP -- the protocol was written with the assumption that users only need to be reachable while they are connected to the server. Some XEP extensions have added partial workarounds, but the protocol as a whole is poorly suited to mobile clients. (This has been a well-known limitation since at least 2014.) You may want to consider alternatives.
I am trying to make an extension on my iOS app with Zebra iMZ320 printer. I followed developers guide of zebra. However ı got an error about SDK.
Here is my code:
- (IBAction)buttonPressed:(id)sender {
NSString *serialNumber = #"";
//Find the Zebra Bluetooth Accessory
EAAccessoryManager *sam = [EAAccessoryManager sharedAccessoryManager];
NSArray * connectedAccessories = [sam connectedAccessories];
for (EAAccessory *accessory in connectedAccessories) {
if([accessory.protocolStrings indexOfObject:#"com.zebra.rawport"] != NSNotFound){
serialNumber = accessory.serialNumber;
break;
//Note: This will find the first printer connected! If you have multiple Zebra printers connected, you should display a list to the user and have him select the one they wish to use
}
}
// Instantiate connection to Zebra Bluetooth accessory
id<ZebraPrinterConnection, NSObject> thePrinterConn = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
// Open the connection - physical connection is established here.
BOOL success = [thePrinterConn open];
// This example prints "This is a ZPL test." near the top of the label.
NSString *zplData = #"^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
NSError *error = nil;
// Send the data to printer as a byte array.
success = success && [thePrinterConn write:[zplData dataUsingEncoding:NSUTF8StringEncoding] error:&error];
if (success != YES || error != nil) {
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[errorAlert show];
}
}
However when I try to print I got an error from last NSError variable. It is in write function.
domain: "ZSDK_API_ERROR_DOMAIN" - code: 1
Can someone help? Thanks in advance.
I've had the same problem, and my solution was to make a function with the code provided by ZEBRA and call this function in a different thread on the button that the user presses.
-(IBAction)buttonPressed:(id)sender {
[NSThread detachNewThreadSelector:#selector(sendZplByBluetooth) toTarget:self withObject:nil];
}
-(void)sendZplByBluetooth{
//Zebra Code Here
}
It was very expensive to realize that, I hope it helps you.
Try using zebra-toolkit. It will save you a lot of trouble with managing the printer and using ZPL.
In iOS app,
Anytime I call this function to open app store,
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms-apps://app-url"]];
The Original app will be deactivated.
The user will then have to restart the original app after they exit the App Store.
It’s very inconvenient way of installation.
Is there any way to open App Store links without leaving the app?
For example, opened as popup window,
after installation just close the popup window, and I can see the original app.
Updated :
I found a great example!
Like this game's popup.
Yes, we can open an App store link without leaving the existing app in IOS 6+.
you can use below for it.
#import <StoreKit/StoreKit.h>
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
storeController.delegate = delegate;
NSDictionary *productParameters = #{ SKStoreProductParameterITunesItemIdentifier : appStoreID };
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
//Handle response
}
Thanks
My version is here.
1) #import <StoreKit/StoreKit.h> and set SKStoreProductViewControllerDelegate
2) add delegate response method,
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
// if user do cancel, close it
[viewController dismissViewControllerAnimated:YES completion:nil];
}
3) add store open code.
void SomeClassName::openAppStore(string appStoreId, string appUrl)
{
// below iOS 6.0
NSString *appUrlStatic = [NSString stringWithUTF8String:appUrl.c_str()];
// iOS 6.0 or above, appstore id is 9-digin number
NSString *appId = [NSString stringWithUTF8String:appStoreId.c_str()];;
// check SKStoreProductViewController API exist or not
if(NSClassFromString(#"SKStoreProductViewController")) {
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
storeController.delegate = self;
NSDictionary *productParameters = #{ SKStoreProductParameterITunesItemIdentifier : appId };
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
if (result) {
[self presentViewController:storeController animated:YES completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:#"Error Occur"
message:#"Error to open App Store."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles: nil] show];
}
}];
[storeController release];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appUrlStatic]];
}
}
I've done more than three days worth of research to fix my problem and I haven't seen anyone with a solution to my problem. The Browser invites an Advertiser, the Advertiser accepts, and the MCSession changes to a connected state. However, once the MCBrowserViewController is closed (by either the cancel or the done button), the MCSession disconnects. As long as I don't close the MCBrowserViewController, the MCSession stays connected. I don't understand why or how this works and I've even tried debugging the process, but it got too deep into threads for me to understand.
Please tell me it's just something wrong with my code.
-(void)setUpMultiPeer{
self.myPeerID = [[MCPeerID alloc] initWithDisplayName:pos];
self.mySession = [[MCSession alloc] initWithPeer:self.myPeerID];
self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:#"svctype" session:self.mySession];
self.advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:#"svctype" discoveryInfo:nil session:self.mySession];
self.browserVC.delegate = self;
self.mySession.delegate = self;
}
-(void)dismissBrowserVC{
[self.browserVC dismissViewControllerAnimated:YES completion:nil];
}
-(void)browserViewControllerDidFinish:(MCBrowserViewController *)browserVC{
[self dismissBrowserVC];
}
-(void)browserViewControllerWasCancelled:(MCBrowserViewController *)browserViewController{
[self dismissBrowserVC];
}
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{
if (state == MCSessionStateConnected) {
NSLog(#"Connected!");
//Not entirely sure about this next line...
self.mySession = session;
}
else if (state == MCSessionStateNotConnected){
NSLog(#"Disconnected");
dispatch_async(dispatch_get_main_queue(), ^(void) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Somebody Left!"
message: [[NSString alloc] initWithFormat:#"%#", [peerID displayName]]
delegate: nil
cancelButtonTitle:#"Got it"
otherButtonTitles:nil];
[alert show];
});
}
}
//Called by a UIButton
-(IBAction)browseGO:(id)sender {
[self setUpMultiPeer];
[self presentViewController:self.browserVC animated:YES completion:nil];
}
//Called by a UISwitch
-(IBAction)advertiseSwitch:(id)sender {
if (_advertiseSwitcher.on) {
[self setUpMultiPeer];
[self.advertiser start];
}
else{
[self.advertiser stop];
}
}
I have also attempted using a unique MCSession for each the Browser and the Advertiser, but with no success.
What I did to solve my problem was start over from ground zero. Waiting on an answer from StackOverflow and from the Apple Developer Forum was taking too long, so I went back to what worked at the very beginning and I will build up from there once more.
Here is a link for an awesome tutorial that I found. I hope this helps someone solve their problem.
However, if anyone sees anything utterly wrong with my code in the question PLEASE DO TELL! I want to know what was causing that bug so that I can learn from my mistakes.
Thank you for stopping by and reading this question.
I have found a services from Google which provides to access to Google APIs for various Google Services. I could set up a project in iPhone and create API access for iOS applications (via OAuth2.0) and native applications. I wanted to use the native API for my iPhone app. It API gives me email,fullname,firstname,lastname,google_id,gender,dob,profile_image. How do I use these in my iPhone Application, Any sample apps, snippets available?
Please help me.
Here is my code :
-(void) loadGmail_Login
{
NSString *keychainItemName = nil;
if ([self shouldSaveInKeychain]) {
keychainItemName = kKeychainItemName;
}
// For GTM applications, the scope is available as
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GTMOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GTMOAuthAuthentication *auth;
auth = [GTMOAuthViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName];
GTMOAuthViewControllerTouch *viewController = [[[GTMOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuthAuthentication *)auth
error:(NSError *)error
{
if (error != nil)
{
// Authentication failed (perhaps the user denied access, or closed the
// window before granting access)
NSLog(#"Authentication error: %#", error);
NSData *responseData = [[error userInfo] objectForKey:#"data"]; // kGTMHTTPFetcherStatusDataKey
if ([responseData length] > 0) {
// show the body of the server's authentication failure response
NSString *str = [[[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"%#", str);
}
[self setAuthentication:nil];
}
else
{
// save the authentication object
[self setAuthentication:auth];
// Just to prove we're signed in, we'll attempt an authenticated fetch for the
// signed-in user
[self doAnAuthenticatedAPIFetch];
}
}
- (void)doAnAuthenticatedAPIFetch
{
NSString *urlStr;
// Google Contacts feed
//
// https://www.googleapis.com/oauth2/v2/userinfo
urlStr = #"http://www.google.com/m8/feeds/contacts/default/thin";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[mAuth authorizeRequest:request];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"API response: %#", str);
GGCXml_Adaptor *localAlphabetXMLParser = [[GGCXml_Adaptor alloc] init];
[localAlphabetXMLParser processBooksXML:data];
[localAlphabetXMLParser release];
// [self updateUI];
} else {
// fetch failed
NSLog(#"API fetch error: %#", error);
}
}
- (void)setAuthentication:(GTMOAuthAuthentication *)auth {
[mAuth autorelease];
mAuth = [auth retain];
}
First you will need to get token from Google API, For this 1st step you will have to follow this tutorial and in the end of this link there is whole source code for iOS for getting token from google API
http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
Then in the next step you have to send that token to Google API to request user Data, I just needed the first step So I am sharing my searchings
Try this Tutorial and Source code Link.. It's works fine for me.
1. Tutorial Reference: http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
2. Api Reference : https://code.google.com/apis/console/
3. Source code: https://github.com/emysa341/Login-with-gmail-google-g--using-oath-2.0-protocol/archive/master.zip
i think this will help anybody else
Follow the below steps to integrate gmail with your application .
1.Add following classes to you project .
GTMHTTPFetcher.h , GTMHTTPFetcher.m ,GTMOAuth2Authentication.h, GTMOAuth2Authentication.m,GTMOAuth2SignIn.h,GTMOAuth2SignIn.m,GTMOAuth2ViewControllerTouch.h,GTMOAuth2ViewControllerTouch.m,GTMOAuth2ViewTouch.xib,SBJSON.h , SBJSON.m
you will get these classes here : https://github.com/jonmountjoy/Force.com-iOS-oAuth-2.0-Example
Note : if you are working under ARC Environment then you have to disable the ARC for following files :
GTMHTTPFetcher.m , GTMOAuth2Authentication.m , GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.m
To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.
2. add the following frameworks
security.framework , systemConfiguration.framework
3. Register your app to google api console …. here : https://code.google.com/apis/console
Then go to ApiAccess section , create client id for iOS app .
then you will get clientID, ClientSecret and RedirectUrl
**4. Now it's time for coding . . . .**
create a signIn button in your controller and set the action for that . Here when the user click the button SignInGoogleButtonClicked method gets called .
//import GTMOAuth2Authentication , GTMOAuth2ViewControllerTouch
#define GoogleClientID #"paster your client id"
#define GoogleClientSecret #"paste your client secret"
#define GoogleAuthURL #"https://accounts.google.com/o/oauth2/auth"
#define GoogleTokenURL #"https://accounts.google.com/o/oauth2/token"
-(void) SignInGoogleButtonClicked
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = #"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:#"google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
auth.scope = #"https://www.googleapis.com/auth/plus.me";
GTMOAuth2ViewControllerTouch * viewcontroller = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:#"GoogleKeychainName" delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewcontroller animated:YES];
}
//this method is called when authentication finished
- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error
{
if (error != nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert !"
message:#"success"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}