2016-11-30

Fix the Build Error of OpenCV iOS: OSError: [Errno 2] No such file or directory

If you are building th opencv for iOS on MacOS, and met the following build error:

My-MacBook-Pro:OpenCV My$ python opencv/platforms/ios/build_framework.py ios
Executing: ['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DIOS_ARCH=armv7', '-DCMAKE_TOOLCHAIN_FILE=/Users/Shared/AppCofe/Study/OpenCV/opencv/platforms/ios/cmake/Toolchains/Toolchain-iPhoneOS_Xcode.cmake', '-DENABLE_NEON=ON', '/Users/Shared/AppCofe/Study/OpenCV/opencv', '-DCMAKE_C_FLAGS=-fembed-bitcode', '-DCMAKE_CXX_FLAGS=-fembed-bitcode'] in /Users/Shared/AppCofe/Study/OpenCV/ios/build/armv7-iPhoneOS
============================================================
ERROR: [Errno 2] No such file or directory
============================================================
Traceback (most recent call last):
  File "opencv/platforms/ios/build_framework.py", line 88, in build
    self._build(outdir)
  File "opencv/platforms/ios/build_framework.py", line 82, in _build
    self.buildOne(t[0], t[1], mainBD, cmake_flags)
  File "opencv/platforms/ios/build_framework.py", line 138, in buildOne
    execute(cmakecmd, cwd = builddir)
  File "opencv/platforms/ios/build_framework.py", line 34, in execute
    retcode = check_call(cmd, cwd = cwd)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 535, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception

OSError: [Errno 2] No such file or directory


Here is the solution to save your time:

in terminal install CMake
My-MacBook-Pro:OpenCV My$ brew install cmake

2016-10-18

Apple Blocked The 41 App URL Scheme on iOS 10.

from iOS 10 Apple has blocked the following URL scheme for developer to launch or access.

  • voicememos,
  • x-tips-widget,
  • stocks,
  • prefs,
  • passuiservice,
  • facegallery,
  • clock-stopwatch,
  • photos-migrate-iphoto,
  • mobilephone-recents,
  • mobilephone-favorites,
  • vmshow,
  • mobilephone,
  • x-apple-mail-forward,
  • x-apple-mail,
  • x-maps-category,
  • x-maps-bulletin,
  • x-maps-reopen,
  • telemergencycall,
  • x-tips-bulletin,
  • contact,
  • camera,
  • clock-timer-running,
  • clock-alarm,
  • clock-worldclock,
  • x-apple-mail-message-id,
  • iclouddriveapp,
  • webclip,
  • bridge,
  • photos,
  • photos-event,
  • com-apple-mobilesafari-tab,
  • x-mail-continuation-payload,
  • x-apple-mail-reply,
  • calinvite,
  • calinvitelist,
  • webapp,
  • x-apple-mail-vip-messages,
  • x-apple-mail-vip-settings,
  • clock-timer,
  • clock-sleep-alarm,
  • weather
You need think about how to use this private url scheme any more.
What I most care about is "prefs://" which allow users to direct to system settings in the earlier version iOS 7, 8, 9.

I think the hacking method can be workaround this limitation. but I don't know whether the ipa can pass apple submission review.

and of cause I saw a lot of  launcher application on iOS 10 has use the similar workaround. 
e.g:

https://itunes.apple.com/us/app/launcher-notification-center/id905099592?mt=8
see the what's new

What's New in Version 2.2.3

Good news! We now have a workaround for the system launchers that didn't work on iOS 10 and they now work again with this release. Please note that this workaround may be temporary depending on what changes come up in future versions of iOS 10






2016-09-27

九条谷歌Adsense广告的政策解读 Google Adsense Policy



#1 Don’t click on your own ads
#1不要点击自己的广告
-不要点击自己的网站或者应用内的广告,或者让其他人帮忙点击
-你自己的点击行为并不会计广告收入,但是会被谷歌列入不良记录。

#2 Think like a user
#2从用户角度反省自己的服务(网站或者应用)
- 提供有用的内容,有价值有意思的服务或者内容
- 让用户更容易的找到他们想要的内容

#3  Keep it family-safe and legal
#3 让您的服务不能危害社会和违反法律

#4 Maximise content, not ads per page
#4内容为主,不要在每一个页面添加广告
- 创建新颖有趣有相关性的内容
- 定期更新

#5 Avoid deceptive layouts
#避免诱骗点击的布局
-不要讲广告放置在图片附近
-让广告远离游戏,图片展示,以及其他重度点击的内容
e.g: 不要让广告放置在导航栏旁边

#6 Avoid site layouts that push content below the fold
不要让网站首页就是广告,内容应该在第一页。
避免误点击

#7 Don’t duplicated content
不要重复制造内容。

#8 Track your traffic & Invalid click activity
#8 关注并监控您的流量
-您的所有流量应该是自然量Organic
-尽早发现不良的流量。
-谷歌能够判断出来无效点击


#9 Don’t modify the AdSense code
#不要修改您的广告代码
 -除非你100%确认您够了解这样做会带来潜在的问题。


常见的谷歌政策警告
#1 广告放置在图片内容之上(Ads placed on images that are primarily dynamic content)
#2 性相关内容(Sexual content)
#3 恶意布局(Deceptive layout)
#4 恶意吸引眼球(Unnatural attention)
#5 不实文本(Mislabeling)
#6 版权内容(Copyrighted material)
#7 明确指向性的文本内容(Explicit text:  Text descriptions including erotic stories,jokes or discussions, or excessive use of profanity)
#8 暴力内容(Violent content)

#9 在错误信息页面添加广告(Thank you, Exit or Error pages)


2016-09-23

How to fix Cocoapod command: pod update --verbose failed?

[Problem]

StevenCs-MacBook-Pro:src StevenC$ pod update --verbose
Update all pods
  Preparing

Re-creating CocoaPods due to major version update.

Updating local specs repositories

Updating spec repo `master`
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-core-1.0.1/lib/cocoapods-core/github.rb:105:in `rescue in modified_since_commit'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-core-1.0.1/lib/cocoapods-core/github.rb:100:in `modified_since_commit'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-core-1.0.1/lib/cocoapods-core/master_source.rb:32:in `requires_update?'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-core-1.0.1/lib/cocoapods-core/master_source.rb:14:in `update'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/sources_manager.rb:88:in `block (2 levels) in update'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/user_interface.rb:63:in `section'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/sources_manager.rb:87:in `block in update'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/sources_manager.rb:86:in `each'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/sources_manager.rb:86:in `update'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer/analyzer.rb:220:in `block in update_repositories'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer/analyzer.rb:218:in `each'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer/analyzer.rb:218:in `update_repositories'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:147:in `block in resolve_dependencies'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/user_interface.rb:63:in `section'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:146:in `resolve_dependencies'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:114:in `install!'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/command/update.rb:60:in `run'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/claide-1.0.0/lib/claide/command.rb:334:in `run'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/lib/cocoapods/command.rb:50:in `run'
/Users/StevenC/.rvm/gems/ruby-2.2.1/gems/cocoapods-1.0.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
/Users/StevenC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'

/Users/StevenC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'

[soluton]:

add the following command parameter
--no-repo-update

so you should use:    pod update --verbose --no-repo-update

2016-09-22

Apple Officially Disable the Settings URL Scheme Only Allow in Custom Keyboard Extension



Since iOS 10, iOS developer can not use URL Scheme to open Settings in their own iOS apps.


The reason is URL schemes for iPhone/iPad Settings are considered Private API which against the Apple Developer Guide.

iOS 10,  here is the only way to open settings in Apple iOS Developer's app:

Use the const string to open App's own setting:

In Swift:
UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
In Objective-C
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
So don't waste time to search the solution for the "jump" or "redirect" users to specific settings with traditional way.


But one more interesting things: on  iOS 10 simulator, you can still working the "redirect" users to settings with the following method.




For more details: Apple Developer Technical Q&A QA1924

Reference Doc: Full List Of Settings URL schemes


FYI:

I am developing a Today Widget to open user's WiFi & Mobile Usage Settings, it really working fine on iOS 9 or earlier version and partially tested in iOS 10 beta Simulator with XCode 8.

When I prepare to publish this app on Apple Store, iOS 10 released, I tested my widget on my iPhone 5 16G real device, my nightmare coming. You can imaging how dark is it to me!!!

I searched on Google & stackoverflow one week try to find a solution. Until now, I wrote this article for those who want to do the same thing as me.

Don't Waste Time on Settings URL Scheme Solution!

Thank You Apple, you ruined my first app on Apple Store!

I quit my job to start a studio and try to make small system level app to improve user's experience.

Now it seem I should do another thing. how bad it is!

and my bad luck is not stopped, I purchased iPhone 6S for my mum, but the phone is broken, can not connect to WiFi and Bluetooth, I had to wait for returned from the apple repair factory.

2016-09-19

FBAudienceNetwork Facebook Audience Network Crash 4.15.0 SDK Fatal Crash on iOS 10

Crash Happened on 

FBAdPlacementDefinition.m line 110
__47-[FBAdPlacementDefinition ingestPlacementData:]_block_invoke.103


Error:

2016-09-20 09:51:39.826 XXXAPP[40863:1427254] -[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x61000005e810
2016-09-20 09:51:39.829 XXXAPP[40863:1427254] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x61000005e810'
*** First throw call stack:
(
0   CoreFoundation                      0x000000011425134b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x0000000113cb221e objc_exception_throw + 48
2   CoreFoundation                      0x00000001142c0f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x00000001141d6c15 ___forwarding___ + 1013
4   CoreFoundation                      0x00000001141d6798 _CF_forwarding_prep_0 + 120
5   XXXAPP                         0x000000010e6b88c8 __47-[FBAdPlacementDefinition ingestPlacementData:]_block_invoke.103 + 207
6   libdispatch.dylib                   0x000000011495d980 _dispatch_call_block_and_release + 12
7   libdispatch.dylib                   0x00000001149870cd _dispatch_client_callout + 8
8   libdispatch.dylib                   0x00000001149678d6 _dispatch_main_queue_callback_4CF + 406
9   CoreFoundation                      0x00000001142154f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
10  CoreFoundation                      0x00000001141daf8d __CFRunLoopRun + 2205
11  CoreFoundation                      0x00000001141da494 CFRunLoopRunSpecific + 420
12  GraphicsServices                    0x0000000116148a6f GSEventRunModal + 161
13  UIKit                               0x0000000111895f34 UIApplicationMain + 159
14  XXXAPP                         0x000000010e5f202f main + 111
15  libdyld.dylib                       0x00000001149d368d start + 1
16  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException


Solution:
The reason is FBAudienceNetwork Issues.
Try to update to  FAN  4.15.1 

Google Firebase Admob GADBannerView Fail to receive Ad





@property(nonatomic,strong)GADBannerView  *bannerView;
@end

@implementation ViewController

- (void)viewDidLoad {
   ....
    [GADMobileAds configureWithApplicationID:@"ca-app-pub-YYYYYYY~YYYYYYY"];
    _bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    _bannerView.center = CGPointMake(self.view.center.x, _adSize.size.height/2.f + 44/2.f + 50/2.f);
    _bannerView.adUnitID = @"ca-app-pub-XXXXXXXXXX/XXXXXXXX";
    _bannerView.rootViewController = self;
    _bannerView.delegate = self;
    
    GADRequest * request = [GADRequest request];
    request.testDevices = @[kGADSimulatorID];
    [_bannerView loadRequest:request];
    [self.view addSubview: _bannerView];
}


#pragma mark - 
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
    NSLog(@"Admob Ad was loaded and ready to be displayed");
}

- (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"Admob Ad failed to load");
}

Error:

Error Domain=com.google.ads Code=13 "Request Error: Received invalid response." UserInfo={NSLocalizedDescription=Request Error: Received invalid response., NSLocalizedFailureReason=Request Error: Received invalid response.}

Solution:

1. Make Sure your  adUnitID and ApplicationID are correct.
2. Add  request.testDevices = @[kGADSimulatorID]; 
3. iOS 9 or iOS 10 app please in Info.plist  add "App Transport Security Settings" - "Allow Arbitrary Loads" set to "Yes"

You will get the test ads





2016-09-18

iOS 10 Today Extension(Today Widget) can not jump to WiFi settings.

Even if you can run the following code on iPhone simulator.

#pragma mark - Action
-(IBAction)actionSetting:(id)sender {
    NSURL * urlWiFiSetting = [NSURL URLWithString://@"prefs:root=WIFI"
                              @"prefs:root=MOBILE_DATA_SETTINGS_ID"
                              ];
    if (urlWiFiSetting) {
        [self.extensionContext openURL:urlWiFiSetting completionHandler:^(BOOL success) {
        }];
    } else {
        NSAssert(true, @"Not Support UIApplicationOpenSettingsURLString");
    }}

But when you run it on real device, you may get the following error:

2016-09-19 02:49:59.564568 Today Extension[4633:766201] __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"

(lldb) 


iOS 10 Apple disable the shortcut for app to jump into.

No way to fix this issue, unless you can report a bug to Apple Bug Report system.