[英]How to set lock screen , wallpaper and Ringtone programmatically in iPhone?
在iPhone中我們是否可以通過編程方式設置鎖屏,壁紙和鈴聲?
如果是 ,那么請告訴我如何設置它們?
這一切都可以輕松完成,但Apple會拒絕。
可以通過改變com.apple.SpringBoard.plist
來更改ringtone
,特別是ringtone
鍵。
以下代碼可用於讀取自定義鈴聲的實際鈴聲標題(由iTunes同步)。
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;
壁紙可以覆蓋:
NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
這些示例用於我的一個Cydia應用程序中。 對他們來說並不是更多,但這些應該讓你朝着正確的方向前進。
由於iOS的變化, WrightsCS的答案在某些時候停止了工作。 不幸的是,如果您希望使用未記錄的功能,則必須使用此功能。
如果您仍然需要這樣做,僅適用於非App Store應用程序 ,此代碼適用於iOS 9.3。 但它可能會在任何未來的iOS版本中停止工作。 (見下面的評論:不再在iOS 10中工作)
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];
Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
您需要將私有API標頭添加到項目中。 您通常可以通過一些搜索在線找到這些, 例如,在這里 。
在上面的例子中, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:]
被調用的3參數:3表示圖像應同時用於鎖定和主畫面。 1表示僅鎖定屏幕。 2表示僅主屏幕。
有關我動態打開此框架的原因的說明,請參閱此處的相關答案 。
我沒有關於鈴聲的答案。 這應該是一個單獨的問題:完全不同的API在起作用。
如果你可以檢查PLStaticWallpaperImageViewController
請使用私有api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.