I'm building a multi-tier enterprise application using Spring. I have different layers: Controller, Business and Provider. Within the application I've built a custom error handling mini-framework that is based on a single RuntimeException which has an error code to discriminate different kind of errors.

Error codes are enums implementing this interface:

public interface ErrorCode {
    public int getNumber();
    public String getDeveloperMessage();
    public String getHelpURL();
    public boolean isSystemError();
}

So for example I have:

public enum SystemErrorCode implements ErrorCode{
    E_UNKNOWN_ERROR(10000, "Unkwown internal error", true),
    E_MISSING_ARGUMENT(10001, "Missing argument", true),
    E_INVALID_ARGUMENT(10002, "Invalid argument", true),
    E_CONTEXT_NO_TENANT(10003, "No tenant in context", true),
    E_CONTEXT_TENANT_CHANGE(10004, "Tenant change attempt", true),
    E_CONTEXT_ALREADY_INITIALIZED(10005, "Tenant already initialized", true),
    E_NOT_IMPLEMENTED(10005, "Feature not implemented", true),
    ...
}

The exception class itself look like this (getters, constructors, and utility methods are stripped out for brevity):

public class EngineRuntimeException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private final String incidentReportId;
    private final ErrorCode code;
    private final Map<String, Object> additionalInfo;

    ...

    public static EngineRuntimeException wrap(Throwable exception, ErrorCode errorCode) {
        if(exception instanceof EngineRuntimeException) {
            EngineRuntimeException se = (EngineRuntimeException)exception;
            if(errorCode != null && errorCode != se.getCode()) {
                return new EngineRuntimeException(exception.getMessage(), exception, errorCode);
            }
            return se;
        } else {
            return new EngineRuntimeException(exception.getMessage(), exception, errorCode);
        }
    }


    public static EngineRuntimeException wrap(Throwable exception) {
        return wrap(exception, SystemErrorCode.E_UNKNOWN_ERROR);
    }

Using the wrap utility method I can easily encapsulate exceptions in the different layers without loosing the original stack and without having it dirty by rethrowing or incapsulating exception more than once.

try {
  if(a == null) {
    throw new EngineRuntimeException(SystemErrorCode.E_UNKNOWN_ERROR, "blah, blah, blah");
  }

  // Some other code that can throw exceptions (checked or unchecked),
  // these exceptions will be wrapped inside EngineRuntimeException if they
  // are not already of that type.

} catch (Exception ex) {
    throw EngineRuntimeException.wrap(ex);
}    

To recap, each layer has a safety boundary try-catch that wraps Exceptions into EngineRuntimeException, just rethrowing what is already an EngineRuntimeException.

The question is: where should I log the exception? I want to log the exception only once so I was thinking about do the logging stuff inside the constructor of EngineRuntimeException class itself. Is that a bad idea? Is it better to do the logging stuff only in the catch blocks of the layer boundaries?

Also I don't want to simply log using a log4j but I want to use a service (@Service) injected by spring so that I can decide to do something more than just logging on file system. How can I do that since I can't make spring inject something in a class I have created with the "new" instruction.

For this example lets say my Core Data model is this:

Person
------  
- firstName  (string)
- lastName (string)  

- address (to-one relationship with Address)  

Address  
-------  
- streetName  (string)
- streetNumber (int)  

- person (to-one relationship with Person)  

Now for the next version of my app, I would like to simplify my model to be:

Person
------  
- firstName  (string)
- lastName (string)  
- address (string) 

As you can see I removed the Address entity from my model scheme and added a "address" string property in Person instead of the to-one relationship with Address entity.

My question is how do do this kind of migration?

Of course I need to adjust my model for the new structure so what I'm thinking to do is to go over all my Person object and do something like:

for (Person *per in allPersons) {    
   NSString *stName = per.address.streetName;  
   NSString *stNum = per.address.streetNumber;
   per.address = [NSString stringWithFormat:@"%@ %@", stName, stNum];
}

Problem is the address entity is no longer exist in my new scheme, so how can I do per.address ?

I suppose I need to use the migration manager or mapping model, just not sure how it will help me, and how to use it.
I'll appreciate a simple example for this kind of use case.

I've got a phonegap app that's been working for ages but suddenly I keep getting force quit. I can't say when it first came in (so I don't know what i've changed since it happens).

Basically the app loads fine then gets to a point after about 10 seconds when it force quits with no error.

What's worse, i'm using phonegap build so debugging is providing to be a right pain. I can't not do it in phonegap build as i'm too reliant on the plugins being used.

This is what i've managed to get out of the iphone console

Sep  4 13:54:14 Haydens-iPhone AppName[529] <Warning>: THREAD WARNING: ['org.apache.cordova.facebook.Connect'] took '65.408936' ms. Plugin should use a background thread.
Sep  4 13:54:14 Haydens-iPhone AppName[529] <Warning>: THREAD WARNING: ['InAppPurchase'] took '33.147217' ms. Plugin should use a background thread.
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: THREAD WARNING: ['Geolocation'] took '31.754883' ms. Plugin should use a background thread.
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]: Getting products data
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]: Set has 2 elements
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]:  - newpet002
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]:  - instantpet001
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]: Starting product request...
Sep  4 13:54:15 Haydens-iPhone AppName[529] <Warning>: InAppPurchase[objc]: Product request started

Sep  4 13:54:15 Haydens-iPhone AppName[529] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument'
    *** First throw call stack:
    (0x2e8aaf83 0x39125ccf 0x2e8aaec5 0x2f22522b 0x2f225115 0x9067b 0x906ff 0x9406d 0xb9f49 0xb91af 0xb71f7 0xbb6e7 0xbb621 0xbbc5b 0x2f1eafc3 0x2f1eaf07 0x2f1eae21 0x2e5110e7 0x2e50fcf7 0x2e7de8f1 0x2e4a76bb 0x2e4a7579 0x2e4a740d 0x2e87620b 0x2e8756db 0x2e873ecf 0x2e7deebf 0x2e7deca3 0x33738663 0x3112b14d 0x9323f 0x39632ab7)

I am using Swift and I want to be able to load a UIViewController when I rotate to landscape, can anyone point me in the right direction?

I Can't find anything online and a little bit confused by the documentation :s

Any advice would be greatly appreciated :)

Thanks, Dave

I have gone through a lot questions regarding the clean up of RAM programmatically and the answer that I got was No its not possible.But recently I got to see one app which is doing memory cleanup.It is live and approved by apple and is showing the free and used RAM space and after cleaning it frees some memory from the phone.On the other hand it is cleaning the junk files too.

Below is the alert that I am getting when I delete the junk files in that app.

One more thing in my study I found that the apps run in a sand box mode and we can't delete the temp files of other apps.But this app is supposed to be doing the same thing.Below is the screen shot of the alert that it gives when user asks for Deleting Temp Files.

So my question is that Is cleaning of RAM,junk files or Temp files of other apps is possible programmatically now or its just a fake call.My company is insisting me to come to a conclusion but I am confused between What I see (the cleaning app) and what I read (the previous stackoverflow questions and blogs).

I have problem with textField and sending request to my server. This is my situation: I have connection between my APP and server by JSON protocol. I send request by POST method, and i'm sending in this: message JSON. I must send JSON in this form: {“pin”:”xxxx”, “uuid”:”yyyy”}. And now it's my question: i wrote pin number in textField, but i don't know how to put this pin number which one i wrote in textField to my JSON 'message'. Anyone could help me?

I have two buttons in my custom-made UITableViewCell.

Each button click should call the desired segue.

I setup a delegate on a cell like this:

CustomCell.h

@protocol CustomCellDelegate
-(void)seeQuestions;
-(void)seeLessons;
@end

@interface CustomCell : UITableViewCell
@property (weak, nonatomic) id <CustomCellDelegate> delegate;
- (IBAction)seeQuestions:(UIButton *)sender;
- (IBAction)seeLessons:(UIButton *)sender;

CustomCell.m

- (IBAction)seeQuestions:(UIButton *)sender {
[self.delegate seeQuestions];
}

- (IBAction)seeLessons:(UIButton *)sender {
[self.delegate seeLessons];
}

Now, in the ViewController class, where I have my UITableView, showing the custom cell, I import the CustomCell.h file, and connect delegates

ViewController.h

#import "CustomrCell.h"

@interface ViewController : UIViewController <CustomCellDelegate>

@property (strong, nonatomic) IBOutlet UITableView *tableView;
-(void)seeQuestions;
-(void)seeLessons;
@end

ViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

CustomCell *cell = (CustomCell *)[tableView     dequeueReusableCellWithIdentifier:@"CustomCell"];
cell.delegate = self;

if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
cell.title.text = [NSString stringWithFormat:@"%@",_topicsArray[indexPath.row]];

    return cell;

}

-(void)seeQuestions
{
[self performSegueWithIdentifier:@"seeQuestions" sender:self];
}

-(void)seeLessons
{
[self performSegueWithIdentifier:@"seeLessons" sender:self];
}

But, when the I click the buttons, nothing happens. I am sure Im missing out some realy obvious thing, but after couple of hours staring at my code, i cannot seem to figure out what am I doing wrong. Any suggestions ?

I have an issue with native date picker in HTML5 iOS application. To reproduce this issue just add simple to any html page and follow the steps given,

Steps to Reproduce:
1. add <input type="date" ... /> to any html page
2. go to the page where date picker implemented.
3. click on input element
4. spin any of picker
5. at the last moment, before picker finally stops click Done button

You can now observe that the app is crashing. If anybody have a suggestion to resolve this issue, that would be very much helpful for me. Thanks in advance :)

My project loads a settings bundle which preserves several host addresses, a variable representing host address changed by user's preference, and in app that i set host address as global variable through #define keyword.

The variable defined by #define can't be changed, so what about extern?

Now I want to change the global variable according the value in Settings bundle, how can i implement?

Thanks in advance!

I'm trying to use Size Class to configure a simple UIView in Interface Builder.

This UIView is displayed by a uiviewcontroller which is the root view controller of my widget (set programaticaly).

Whatever Size Class I customize, it is not used and the Any/Any is always used in iPad/iPhone in portrait and landscape.

Are Size Classes supposed to work in Today Extensions ? If so, anyone managed to use it so far ?

My app is already published. I want to add push notification to it. Should I create new app id ?

Please help

Renu

I am getting didFailWithError Please help me

 scanCode = @"123";
    NSString * urlString=[NSString stringWithFormat:@"http://1-dot-digiphoto-01.appspot.com/v1/service/rest/getAlbums/QR/{%@}",scanCode];



NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (!conn)
{
    responseData = nil;
    NSLog(@"Connection Error");

}

How can show any string in right to left languages such as Persian or Arabic in Android or iOS with FireMonkey, I Use Embarcadero Rad Studio XE6 (Delphi) and when I put a TLabel or TEdit and set it's text to "سلام" (Hello in Persian) everything is ok in Windows and Mac but in Mobile platform that is wrong display, in android shows "م ا ل س" and in iOS does not show any thing but space.

Currently I'm working on an App with a MKMapView. I added a singleTab Gesture for hiding the status-, nav- and tab bar and with a LongTab you set an Annotation. But when the user tabs on the Annotation the title of the annotation appears and all bars disappear or appears as well. This should not happen.

Can anyone help me?

Thanks

Code

- (void)viewDidLoad
{
    [super viewDidLoad];

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(handleLongTap:)];
    lpgr.minimumPressDuration = .5;  //How long the user has to press the button
    [_mapView addGestureRecognizer:lpgr];

    self.doubleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleDoubleTap:)];
    self.doubleTap.numberOfTapsRequired = 2;
    self.doubleTap.numberOfTouchesRequired = 1;
    [_mapView addGestureRecognizer:_doubleTap];

    self.singleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleSingleTap:)];
    self.singleTap.numberOfTapsRequired = 1;
    self.singleTap.numberOfTouchesRequired = 1;
    [self.singleTap requireGestureRecognizerToFail: _doubleTap];
    [_mapView addGestureRecognizer:_singleTap];
}

- (void)handleLongTap:(UIGestureRecognizer *)gestureRecognizer
{
    [_mapView removeAnnotations:[_mapView annotations]];

    if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
        return;

    CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];
    CLLocationCoordinate2D touchMapCoordinate =
    [_mapView convertPoint:touchPoint toCoordinateFromView:_mapView];
    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    point.coordinate = touchMapCoordinate;
    point.title = @"Title";

    [self.mapView addAnnotation:point];
}

-(void)handleSingleTap:(UIGestureRecognizer*)gestureView
{
    if (self.navigationController.navigationBar.hidden == YES)
       {
            // hide the Navigation Bar
            [self.navigationController setNavigationBarHidden:NO animated:YES];
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
            _toolBar.hidden = NO;
        }
    else {
            [self.navigationController setNavigationBarHidden:YES animated:YES];
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
            _toolBar.hidden = YES;
    }
}

We are creating an app that will change an existing iPhone photo's EXIF and XMP metadata such as title, tags etc, is there a way to save (or sync) those changes back to the original photos, so that in case user delete the app, the changes can still be preserved.

Searched apple doc, there doesn't seem to have a way to directly alter the metadata of an existing AlAsset, maybe an alternative way is to create a new photo with modified metadata and overwrite the original?

What is the best way to draw a whole CALayer hierarchy to a context (hence a UIImage, PDF)?

My hierarchy contains CATransformLayer, CATextLayers, CAReplicatorLayers and CAShapeLayers.

It looks fine on the screen but I never get it to look the same in the UIImage (and I don't want to use a screenshot-like rendering, since I want the CAShapeLayers and CATextLayers to be rendered as a vertex graphic to PDF)

These are some problems that I'm facing: -The rendering ignores the zPosition property and the zTranslation in the transform, it renders strictly by the order in the sublayers array -My layers have frames/position/transforms mixed and often layers get moved around when rendering -Sometimes CAReplicatorLayers are simply ignored and only the first instance gets rendered to file -As soon as a z value is set in the translation of the transform, that layer scompletely ignores its transfrom and renders itself at (0, 0), I worked around that by manually ordering the layers and setting the zTranslation to 0 but it's not very comfortable.

I hope somebody of you knows an easy and safe way to render everything to a context exactly as it is shown on the screen!

I remember darkly that an earlier version of Xcode provided the option to connect IBActions for UI elements on several different states like when the user pressed down on a button but didn't lift the finger yet, etc. All I see in Xcode 6 is only one IBAction that fires when for example a button was pressed.

I need an IBAction on several buttons that gets called right when the user touches the button, even without lifting the finger.

Is there any way to achieve this?

I am getting battery state as UIDeviceBatteryStateCharging even though my iPhone battery is 100% charged.

It should give me state as UIDeviceBatteryStateFull.

My code is as follows.

[[UIDevice currentDevice]setBatteryMonitoringEnabled:YES];
    int i=[[UIDevice currentDevice] batteryState];
    switch (i)
    {
        case UIDeviceBatteryStateUnplugged:
        {
            NSLog(@"UnpluggedKey");

            break;
        }
        case UIDeviceBatteryStateFull:
        {
            NSLog(@"FullKey");

            break;
        }
        case UIDeviceBatteryStateCharging:
        {
            NSLog(@"ChargingKey");
            break;
        }
        default:
        {
            NSLog(@"UnknownKey");
            break;
        }
    }

    NSLog(@"Battery Status is :%d",i);

I have set up two AdMob accounts with google to add into my apps. The first account I have about £75 in revenue and before I could receive the money Google emailed me to deactivate the account saying that there was invalid activity on my account!!!

OK so I accepted it and opened another account. I Updated my apps and they are currently still in review so no adds from AdMob are even being displayed anywhere and I received the same email from Google saying there is invalid activity on my account. Last time I checked the current revenue was 0.

Has anyone had the same experience and if so can you give me some advice. I really don't know what I am doing wrong.

Thank you.

I can't access www.wmxy.ro to input password and user name from server. Every time in my application i have Authorization Required This server could not verify that you are . . Never ask me password and user.

I have this file: Main.java

package com.wmxy.webviewer_tutorial;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.annotation.SuppressLint;
import android.app.Activity;

public class Main extends Activity {


private static final String TAG="tutorial";

private WebView MainWebview;

private ProgressBar progressBar;


@SuppressLint("SetJavaScriptEnabled") @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Log.i(TAG, "onCreate");
    MainWebview = (WebView) findViewById(R.id.webView);
    MainWebview.getSettings().setJavaScriptEnabled(true);
    MainWebview.getSettings().setBuiltInZoomControls(true);
    MainWebview.getSettings().setSupportZoom(true);
    MainWebview.getSettings().setSaveFormData(true);
    MainWebview.getSettings().setSavePassword(true);
    MainWebview.loadUrl("http://www.wmxy.ro");
    MainWebview.setWebViewClient(new WebViewerClient());
}

@Override
public void onBackPressed() {
    if (MainWebview.canGoBack())
        MainWebview.goBack();
    else
        super.onBackPressed();
}

private class WebViewerClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView weWebView, String url) {
        weWebView.loadUrl(url);
        progressBar.setVisibility(View.VISIBLE);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBar.setVisibility(View.GONE);
    }
}

@Override
protected void onStart() {
    super.onStart();
    Log.i(TAG, "onStart");
}

@Override
protected void onRestart() {
    super.onRestart();
    Log.i(TAG, "onRestart");
}

@Override
protected void onPause() {
    super.onPause();
    Log.i(TAG, "onPause");
}

@Override
protected void onResume() {
    super.onResume();
    Log.i(TAG, "onResume");
}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.i(TAG, "onDestroy");
}

@Override
protected void onStop() {
    super.onStop();
    Log.i(TAG, "onStop");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    MainWebview.saveState(outState);
    Log.i(TAG, "onSaveInstanceState");
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    MainWebview.restoreState(savedInstanceState);
    Log.i(TAG, "onRestoreInstanceState");
}

}

I want to allow only 20% of the video to be buffered. But for some reason my onBufferingUpdate() is not getting called.

Any reason? I am trying to play .m3u8 on VideoView. The video gets played but onBufferingUpdate() is not getting called.

This is my below code

String VideoURL =     "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videoview_main);

    videoview = (VideoView) findViewById(R.id.VideoView);

    pDialog = new ProgressDialog(VideoViewActivity.this);
    pDialog.setTitle("Android Video Streaming POC");
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(
            VideoViewActivity.this);
        mediacontroller.setAnchorView(videoview);
        // Get the URL from String VideoURL
        Uri video = Uri.parse(VideoURL);
        videoview.setMediaController(mediacontroller);
        videoview.setVideoURI(video);

    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

    videoview.requestFocus();
    videoview.setOnPreparedListener(VideoViewActivity.this);
}

@Override
public void onPrepared(MediaPlayer mp) {
    pDialog.dismiss();
    mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
        // show updated information about the buffering progress
        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            Log.e("ERRORRRRRRRRRR", "percent: " + percent);
        }
    });
    videoview.start();
}

Can anyone help ?

Thanks!