Tuesday, October 2, 2018

Prevent files from being backed up to iCloud and iTunes in Swift 4


    func addSkipBackupAttributeToItemAtURL(url){
        
        do {
            var resourceValues = URLResourceValues()
            resourceValues.isExcludedFromBackup = true
            try url.setResourceValues(resourceValues)
        } catch {
            print(error.localizedDescription)
        }
    

    }

        addSkipBackupAttributeToItemAtURL(url)

       url: file url pass and call when store on desired directory 

Wednesday, August 30, 2017

CSV input from cloud or external drive in Android Application



Needs to read external storage permission on file: AndroidMainiest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Now our desired intent "performFileSearch" mehtod call

/**
 * Fires an intent to spin up the "file chooser" UI and select an CSV.
 */
private static final int READ_REQUEST_CODE = 42;

public void performFileSearch() {
 
    // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
    // browser.

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    // Filter to only show results that can be "opened", such as a
    // file (as opposed to a list of contacts or timezones)

    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Filter to show only CSV, using the CSV MIME data type.
    // If one wanted to search for ogg vorbis files, the type would be "image/*".
    // To search for all documents available via installed storage providers,
    // it would be "*/*".


    intent.setType("text/csv"); 
    startActivityForResult(intent, READ_REQUEST_CODE);
}
 
Note the following:
  • When the app fires the ACTION_OPEN_DOCUMENT intent, it launches a picker that displays all matching document providers.
  • Adding the category CATEGORY_OPENABLE to the intent filters the results to display only documents that can be opened, such as CSV files.
  • The statement intent.setType("text/csv") further filters to display only documents that have the CSV MIME data type.

Process Results

After the user selects a document in the picker, onActivityResult() gets called. The resultData parameter contains the URI that points to the selected document. Extract the URI using getData(). When you have it, you can use it to retrieve the document the user wants. For example:

@Override
public void onActivityResult(int requestCode, int resultCode,
        Intent resultData) {

    // The ACTION_OPEN_DOCUMENT intent was sent with the request code
    // READ_REQUEST_CODE. If the request code seen here doesn't match, it's the
    // response to some other intent, and the code below shouldn't run at all.

    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        // The document selected by the user won't be returned in the intent.
        // Instead, a URI to that document will be contained in the return intent
        // provided to this method as a parameter.
        // Pull that URI using resultData.getData().
        Uri uri = null;
        if (resultData != null) {
            uri = resultData.getData();
            Log.i(TAG, "Uri: " + uri.toString());
            readCSVFile(uri);
        }
    }
}



    private void readtFile(Uri uri){

        InputStream inputStream = null;

        try {
            inputStream = getContentResolver().openInputStream(uri);
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    inputStream));
            String line;
            String resultString = null;

            String resultedString = null;
            Log.i("","open text file - content"+"\n");
            while ((line = reader.readLine()) != null) {

                if (resultString == null){
                    resultString = line+"\n";
                }else{
                    resultString = resultString + line+"\n";

                } 
                Log.d("csv file", "CSV File" + line+"\n");            } 
             Log.d("csv file", "Final CSV File" + resultString);
            reader.close();
            inputStream.close();
        } catch (Exception e) {
//            Log.i("csv file", "CSV File" + "Read problem");            e.printStackTrace();
        }
    }
 
 
 


 

Monday, May 22, 2017

iOS application icon change without appstore update on iOS 10.3

In other words, an update is no longer required to push out the new icon artwork.
The seemingly unimportant change opens up a world of new possibilities for interactions with your favorite apps that simply were not possible before.
Taking advantage of the iOS 10.3 SDK, developers can now use a new Instance method to specify the primary app icon as well as one or more alternate icons.
iOS developer Steve Stroughton-Smith explained that apps must ask your permission before changing their icon. Granting permission yields an alert like the one you see below, informing you of an icon change.

So let see, how to change the icon in your app.

If you see in your Info.plist file, Icon files new entity, showing a way you need to put all icon information in plist.




In order to Icon change process, should include here

    switch (sender.selectedSegmentIndex) {
        case 0:
            [[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
        case 1:
            [[UIApplication sharedApplication] setAlternateIconName:@"Test1" completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
        case 2:
            [[UIApplication sharedApplication] setAlternateIconName:@"Test2" completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
           
        default:
            break;
    }
Demo Code

Tuesday, January 17, 2017

Swift some important note.

Who are swift struggling to comment, pragma, .warning, to do or other imports note to write, which one to next time or fix some issue, it's embarrassing to who already working on Objective-C, here we go with some swift important slip.

Comment:

Single line: //
Multi Line: /* here your commommnets*/

Pragma or methods section mark which Objective-C is called #pragma

//MARK:UITableViewDelegate

Warning:

//TODO: this method complete next day 

Logical change or need to fix somethings then:

//FIXME: logical error here, or should update depreciated

Thursday, January 5, 2017

Access resource from main bundle using Swift 3.0


Plist read from the main bundle:

let plistPath = Bundle.main.path(forResource: "plist name", ofType: "plist")
let dataList = :NSArray = NSArray(contentsOfFile: plistPath!)!
print(dataList)

Info Plist access:

let appDisplayName:String = Bundle.main.infoDictionary!["CFBundleDisplayName"] as! String


Monday, November 21, 2016

Dynamic CollectionView Cell size create based on text length size .



Firstly we need to calculate text length and configure to collection view cell size layout.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
        CGSize calCulateSize =[(NSString*)[_categoryList objectAtIndex:indexPath.row] sizeWithAttributes:NULL];
        calCulateSize.width = calCulateSize.width+50; // for better look we add more 50 pixel
        calCulateSize.height = 50; // fixed height
        return calCulateSize;
}



as usual, we implement all of the required collection view delegate and data source, then we see look like collection view cell. demo attached here, if any things need, let me know.


Demo here

Wednesday, November 2, 2016

iOS extension to Host app data share.

Most of the developer struggle data send the extension to Host app, We try to figure out this issue.

Steps:

1. Create  new project ->Xcode->File->New->Project->Single View Application
2. Extension Target add -> File->New->Target->iMessage Extension (also you choose your one)

Host App

1. Info.plist add URL scheme
       <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>url.Identifier</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.avigitsaha.halloweenwallpaperhd.Schemes</string>
            </array>
        </dict>
    </array>

2. AppDelegate.m

 - (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
   
    NSLog(@"options %@",options);
    NSLog(@"URL scheme:%@", [url scheme]);
    NSLog(@"URL query:1234 %@", [url query]);
   
    NSURLComponents *urlComponents;
    NSArray* queryItems;
   
    // init
    urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
    queryItems = [urlComponents queryItems];
   
    for (NSURLQueryItem* item in queryItems)
    {
        if ([[item name] isEqualToString:@"imageId"]){
            NSLog(@"image Id %@",[item value]);
        }
       
        if ([[item name] isEqualToString:@"categoryId"]){
            NSLog(@"Category Id %@",[item value]);
        }
       
    }
    return NO;
}

Extension App

1. UIButton added for host app code here

- (IBAction)openHostAppWithData:(UIButton *)sender {
    NSString *customURL = [NSString stringWithFormat:@"com.avigitsaha.halloweenwallpaperhd.Schemes://"];
   
    NSURLComponents* urlComponents;
    urlComponents = [NSURLComponents componentsWithURL:[NSURL URLWithString:customURL] resolvingAgainstBaseURL:NO];
   
    [urlComponents setQueryItems:@[[NSURLQueryItem queryItemWithName:@"imageId" value:@"1"],[NSURLQueryItem queryItemWithName:@"categoryId" value:@"2"]
                                   ]];
    [self.extensionContext openURL:[urlComponents URL] completionHandler:^(BOOL success){
        NSLog(@"success %d",success);
    }];
}

Here attached Demo project